CMPT 225 Lecture Notes - Lecture 2: Linked List, Memory Management
Document Summary
In mystack. h: class node { public: float data; 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. Node (int x) data = x; next = null; Node* top: make node, point to existing stack, make new node top. // 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 (st. top != null) { // 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 mystack::pop() // change top to next node in list.