COSC-051 Lecture Notes - Lecture 14: Linked List

86 views3 pages

Document Summary

Code for inserting something in the middle of a linked list struct listnode int data; {data = d; next = p} head = temp; // these are pointers void insert(int val, listnode *&head) Listnode *temp, *current; temp = new listnode(val, null); // boundary conditions (checking the first and last item in the list) if (head = = null) // check if the item you want to insert happens to be the first item in the list else if (head > data > val) else temp->next = head; head = temp; current = head; bool done = false; //the -> symbol is a pointer while(!done) current = current > next; current > next=temp; if (current >next = = null) else if(current >next >data <= val) else. // put the new item in!! temp >next = current >next; current >next = temp; done = true; Code for deleting a node (some val) in the middle of a linked 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