Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Linked Lists.

Similar presentations


Presentation on theme: "Chapter 9 Linked Lists."— Presentation transcript:

1 Chapter 9 Linked Lists

2 Outline Abstract Model of a List Obj. Handling the Back of the List
Insertion into a List Linked List (LL) nodes Node Composition Inserting at the Front of a LL Deleting from the Front of a LL Removing a Target Node Handling the Back of the List Designing a New LL Structure Inserting a Node at a Position Circular Doubly LL’s Updating a Doubly LL

3 Abstract Model of a List Object

4 Insertion Into a List by Shifting Vector Storage Elements

5 Linked List Nodes Each Node is like a piece of a chain
Individual Piece Pop Chain To insert a new link, break the chain at the desired location and simply reconnect at both ends of the new piece.

6 Linked List Nodes Removal is like Insertion in reverse.

7 Node Composition An individual Node is composed of two parts, a Data field containing the data stored by the node, and a Pointer field that marks the address of the next Node in the list. Node Class: Page 1049

8 §- singly linked lists - Each node contains a value and a pointer to the next node in the list. - The list begins with a pointer to the first node of the list and terminates when a node has a NULL pointer. 8

9 §- Inserting/Deleting at the front of a singly linked list
- Set the pointer in the new node to the previous value of front. - update front to point at the new node. 2) Erase - assign front the pointer value of the first node, and then delete the node. 9

10 Inserting at the Front of a Linked List

11 Deleting From the Front of a Linked List

12 §- Inserting/Erasing inside a singly linked list
- Maintain a pointer to the current list node and a pointer to the previous node. - Change the pointer value in the previous node. 12

13 Removing a Target Node

14 Handling the Back of the List

15 §- Insert/Delete at the back of a singly linked list
- Maintain a pointer to the last list node that has value NULL when the list is empty. - Assign a “back” pointer the address of the first node added to the list. - To add other nodes at the back: 1) allocate a new node 2) assign the pointer in node “back” to point to the new node 3) assign the pointer “back” the address of the new node. 15

16 Designing a New Linked List Structure

17 Singly LinkedList P1050: LinkedList.h

18 §- Doubly linked lists - provide the most flexible implementation for the sequential list. §- Its nodes have pointers to the next and the previous node, so the program can traverse a list in either the forward or backward direction. - Traverse a list by starting at the first node and follow the sequence of next nodes until you arrive back at the header. - To traverse a list in reverse order, start at the last node and follow the sequence of previous nodes until arriving back at the header. dnode Class 18

19 Inserting a Node at a Position

20 Deleting a Node at a Position

21 Circular Doubly Linked Lists
A Watch Band provides a good Real Life analogue for this Data Structure

22 Circular Doubly Linked Lists
Implemented on a Computer it might look something like this.

23 Updating a Doubly Linked List


Download ppt "Chapter 9 Linked Lists."

Similar presentations


Ads by Google