{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 10 - LECTURE 4 INSERT FOR SORTED LIST Insert into...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 LECTURE 4 • Insert into Sorted Linked List • Delete from Sorted Linked List • Saving a Linked List to a File • Circular Linked List • Dummy Head Linked list • Doubly Linked List 2 INSERT FOR SORTED LIST • Find WHERE to insert • Create a new node • Splice the new node into the linked list Three Steps: 3 FIND WHERE TO INSERT head 12 30 41 56 To insert: 50 4 We use a “current” pointer. If the number X we want to insert is smaller than the current number, then we advance the “current” pointer to the next position. 5 struct listNode; typedef listNode* ptrType; // In header file struct listNode { // In implementation int data; // file ptrType next; }; 6 cur = head; while (X > cur data) cur = cur next; head 12 30 41 66 x 50 cur
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon