Class Notes (811,155)
Canada (494,530)
CMPT 225 (60)
John Edgar (28)
Lecture 2

CMPT 225 Week 2 Lecture 3

2 Pages
Unlock Document

Simon Fraser University
Computing Science
CMPT 225
John Edgar

In MyStack.h: class Node { public: float data; Node* next; Node(float x): data(x), next(NULL) {}; // initialization list, way of initializing data in new obj, comes before body of constructor Node(float x, Node* nd): data(x), next(nd) {}; // does same as above /* first is equivalent to Node (int x) { data = x; next = NULL; } */ }; Node* top; 1. Make node 2. Point to existing stack 3. Make new node top Linked List Implementation of MyStack: (.cpp) MyStack::MyStack(void) { // empty linked list is just nothing; a top pointer which just points to NULL top = NULL; } MyStack::MyStack(const MyStack & st) // copy constructor { top = NULL; // Only make a copy if st is non-empty if ( != NULL) { Node* temp =; Node* newNode; // copy the top newNode = new Node(temp->data, NULL); top = newNode; temp = temp->next; // traverse stack building a new list (copy the rest of it) while (temp != NULL) { newNode->next = new Node(temp->data, NULL); temp = temp->next; newNode = newNode->next; } } } float
More Less

Related notes for CMPT 225

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.