CMPT 225 Lecture Notes - Lecture 2: Linked List, Memory Management

39 views2 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents