COM SCI 32 Lecture Notes - Lecture 7: Linked List

46 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+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents