COM SCI 32 Lecture Notes - Lecture 7: Linked List

44 views2 pages

Document Summary

You cannot cycle through a linked list by using p++ or p-- . To add a node into the middle of the list: void additem(string newitem) if (our list is totally empty) //just use our addtofront() method to add the new node else if (our new node belongs at the very top of the list) Just use our addtofront() method to add the new node else //new node belongs to somewhere in the middle of the list. //link the new node into the list right after the above node. void additem(string newitem) if (head == nullptr //our list is totally empty) Addtofront(newitem); else if (//our new node belongs at the very top of the list) //just use our addtofront() method to add the new node. Addtofront(newitem); else //new node belongs to somewhere in the middle of the list. //use a traversal loop to find the node just above where you want to insert our new ite m.

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