COP3502_7_LinkedList - Computer Science Department University of Central Florida Linked Lists Deleting Nodes COP 3502 Computer Science I Linked

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Science Department University of Central Florida Linked Lists: Deleting Nodes COP 3502 Computer Science I Linked Lists: Deleting Nodes page 2 Linked Lists: Basic Operations Operations Performed on Linked Lists Several operations can be performed on linked lists Add a new node Delete a node Search for a node Counting nodes Modifying nodes and more We will build functions to perform these operations Linked Lists: Deleting Nodes page 3 Linked Lists: Deleting Nodes General Approach: You must search for the node that you want to delete (remember, we are using sorted lists) If found, you must delete the node from the list This means that you change the various link pointers The predecessor of the deleted node must point to the deleted nodes successor Finally, the node must be physically deleted from the heap You must free the node Linked Lists: Deleting Nodes page 4 Linked Lists: Deleting Nodes General Approach: There are 4 deletion scenarios: 1) Delete the first node of a list 2) Delete any middle node of the list Not the first node or the last node 3) Delete the last node of the list 4) A special case when we delete the only node in the list Causes the resulting list to become empty Linked Lists: Deleting Nodes page 5 Linked Lists: Deleting Nodes 4 Cases of Deletion: 1) Delete the first node of a list 6 myList NULL The list after deleting the first node 4 myList NULL The initial list 6 node to be deleted Linked Lists: Deleting Nodes page 6 Linked Lists: Deleting Nodes 4 Cases of Deletion: 1) Delete the first node of a list Think about how you make this happen: myList needs to point to the 2 nd node in the list So we save the address of the 2 nd node into myList Where do we get that address: It is saved in the next of the first node So we take that address and save it into myList 4 myList NULL The initial list 6 node to be deleted Linked Lists: Deleting Nodes page 7 Linked Lists: Deleting Nodes 4 Cases of Deletion: 1) Delete the first node of a list Think about how you make this happen: myList needs to point to the 2 nd node in the list So we save the address of the 2 nd node into myList Where do we get that address: It is saved in the next of the first node So we take that address and save it into myList Finally, we free the 1 st node 4 myList NULL The initial list 6 node to be deleted Linked Lists: Deleting Nodes page 8 Linked Lists: Deleting Nodes 4 Cases of Deletion: 1) Delete any middle node of the list 4 myList NULL The initial list 8 6 node to be deleted 4 myList NULL The list after deletion has occurred 8 Linked Lists: Deleting Nodes page 9 Linked Lists: Deleting Nodes 4 Cases of Deletion: 1) Delete any middle node of the list Think about how you make this happen: Node # 4 (with 4 as data) needs to point to Node # 8 So we save the address of Node #8 into...
View Full Document

This document was uploaded on 09/21/2011.

Page1 / 51

COP3502_7_LinkedList - Computer Science Department University of Central Florida Linked Lists Deleting Nodes COP 3502 Computer Science I Linked

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online