Presentation is loading. Please wait.

Presentation is loading. Please wait.

Doubly Linked Lists or Two-way Linked Lists

Similar presentations


Presentation on theme: "Doubly Linked Lists or Two-way Linked Lists"— Presentation transcript:

1 Doubly Linked Lists or Two-way Linked Lists
12/8/2018 Doubly Linked Lists or Two-way Linked Lists © 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists

2 Doubly Linked List (or Two-way Linked List)
A doubly linked list can be traversed forward and backward Nodes store: element link to the previous node link to the next node Special trailer and header nodes prev next element node trailer header nodes/positions elements © 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists

3 Header and trailer Make implementation easier
Every insertion/deletion is between two nodes Can be implemented without them Save space Need to consider special cases at the beginning and at the end © 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists

4 Insertion p A B C p q A B C What are the instructions? X p q A B X C
Insert a new node, q, between p and its successor. p A B C p q A B C What are the instructions? X p q A B X C © 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists

5 Deletion (don’t forget to deallocate the deleted node)
Remove a node, p, from a doubly linked list. A B C D p A B C p What are the instructions? D A B C © 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists

6 == (equality) struct Person person1, person2;
What is the difference between person1 == person2 Person3 == person4 © 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists


Download ppt "Doubly Linked Lists or Two-way Linked Lists"

Similar presentations


Ads by Google