Download presentation
Presentation is loading. Please wait.
1
Variations of Linked Lists CS 302 – Data Structures Sections 6.2, 6.3 and 6.4
2
Circular Linked Lists Extending a linear linked list to a circular linked list –Make the last node point back to the first node
3
–To have access to both the first and last nodes of the list, make listData point to the last node Circular Linked Lists (cont’d)
4
Doubly-Linked Lists: Node structure info: the user's data next, back: the address of the next and previous node in the list.back.next.info
5
Node structure (cont’d) template struct NodeType { ItemType info; NodeType * next; NodeType * back; };
6
Inserting an item We no longer need to use prevLocation (we can get the predecessor of a node using its back member). prevLocation location
7
Inserting into a Doubly Linked List 1. newNode->back = location->back; 3. location->back->next=newNode; 2. newNode->next = location 4. location->back = newNode;
8
Headers and Trailers Special cases arise when we are dealing with the first or last nodes. Idea: make sure that we never insert or delete the ends of the list! How? Set up dummy nodes with values outside the range of possible values.
9
Headers and Trailers (cont.) Header Node: contains a value smaller than any possible list element. Trailer Node: contains a value larger than any possible list element.
10
Implement a linked list using arrays struct NodeType { ItemType info; NodeType* next; }; David Joshua Leah Miriam Robert
11
A linked list as an array of records: struct NodeType { ItemType info; int next; }; David Joshua Leah Miriam Robert
12
A linked list as an array of records: How would you Insert/Delete items? David Joshua Leah Miriam Robert Can you implement Binary Search efficiently?
13
Why would one implement a linked list using arrays? Integer indices take up less memory than pointers. Store/Read lists to/from files more efficiently.
14
Case Study: Implementing a large integer ADT The range of integer values varies from one computer to another. For long integers, the range is typically [-2,147,483,648 to 2,147,483,647] How can we manipulate larger integers?
15
Case Study: Implementing a large integer ADT (cont.)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.