SlideShare a Scribd company logo
1 of 12
Download to read offline
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 – Data Structures I
Link Lists Gone Wild:
Circular and Doubly
Linked Lists
Linked Lists Gone Wild: Doubly-Linked Lists page 2
© Dr. Jonathan (Yahya) Cazalas
Double-Linked Lists
 Limitations of a singly-linked list include:
 Insertion at the front is O(1)
 insertion at other positions is O(n)
 Insertion is convenient only after a referenced node
 Removing a node requires a reference to the previous
node
 We can traverse the list only in the forward direction
 We can overcome these limitations:
 Add a reference in each node to the previous node,
creating a double-linked list
Linked Lists Gone Wild: Doubly-Linked Lists page 3
© Dr. Jonathan (Yahya) Cazalas
Double-Linked Lists (cont.)
Linked Lists Gone Wild: Doubly-Linked Lists page 4
© Dr. Jonathan (Yahya) Cazalas
Linked Lists
 Here’s a doubly linked list node class:
public class DLLnode {
public int data;
public dll_node next;
public dll_node prev;
// Constructor 1
public DLLnode(int i) {
this(i, null, null);
}
// Constructor 2
public DLLnode(int i, dll_node n, dll_node p) {
data = i;
next = n;
prev = p;
}
}
Each ll_node object has
at least 3 fields:
(1) data field, which
stores information
(2) next field, which is
used to link the nodes
together
(3) previous, which links
to previous node
Linked Lists Gone Wild: Doubly-Linked Lists page 5
© Dr. Jonathan (Yahya) Cazalas
Inserting into a Double-Linked
List
next =
= prev
data = "Harry"
DLLnode
next = null
= prev
data = "Sam"
DLLnode
next =
= prev
data = "Sharon"
DLLnode
DLLnode newNode= new DLLnode("Sharon");
newNode.next = helpPtr;
newNode.prev = helpPtr.prev;
helpPtr.prev.next = newNode;
helpPtr.prev = newNode;
from predecessor
to
predecessor
helpPtr
newNode
Linked Lists Gone Wild: Doubly-Linked Lists page 6
© Dr. Jonathan (Yahya) Cazalas
Removing from a Double-Linked
List
next =
= prev
data = "Bob"
Node
next =
= prev
data = "Harry"
Node
next =
= prev
data = "Sharon"
Node
helpPtr
helpPtr.prev.next = helpPtr.next;
helpPtr.next.prev = helpPtr.prev;
Linked Lists Gone Wild: Doubly-Linked Lists page 7
© Dr. Jonathan (Yahya) Cazalas
A Double-Linked List Class
So far we have worked only
with internal nodes
As with the single-linked class,
it is best to access the internal
nodes with a double-linked list
object
A double-linked list object has data fields:
 head (a reference to the first list Node)
 tail (a reference to the last list Node)
Insertion at either end is O(1)
insertion elsewhere is still O(n)
Linked Lists Gone Wild: Doubly-Linked Lists page 8
© Dr. Jonathan (Yahya) Cazalas
Circular Lists
 Circular double-linked list:
 Link last node to the first node, and
 Link first node to the last node
 We can also build singly-linked circular lists:
 Traverse in forward direction only
 Advantages:
 Continue to traverse even after passing the first or last node
 Visit all elements from any starting point
 Never fall off the end of a list
 Disadvantage: Code must avoid an infinite loop!
Linked Lists Gone Wild: Doubly-Linked Lists page 9
© Dr. Jonathan (Yahya) Cazalas
Circular Lists (cont.)
Linked Lists Gone Wild: Doubly-Linked Lists page 10
© Dr. Jonathan (Yahya) Cazalas
Linked Lists Gone Wild
ISN’T
THAT
GREAT ( )!
That we are finished
with Linked Lists!
Linked Lists Gone Wild: Doubly-Linked Lists page 11
© Dr. Jonathan (Yahya) Cazalas
Daily Demotivator
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 – Data Structures I
Link Lists Gone Wild:
Circular and Doubly
Linked Lists

More Related Content

What's hot

Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechniclavparmar007
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)Waheed Khalid
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureadeel hamid
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingMariano Rodriguez-Muro
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueSelvaraj Seerangan
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure NUPOORAWSARMOL
 

What's hot (20)

Sql ppt
Sql pptSql ppt
Sql ppt
 
Trees
TreesTrees
Trees
 
Data struters
Data strutersData struters
Data struters
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
 
Data structures
Data structuresData structures
Data structures
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Data structure
Data structureData structure
Data structure
 
Database structure
Database structureDatabase structure
Database structure
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Tree data structure
Tree data structureTree data structure
Tree data structure
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and Queue
 
Advanced Trees
Advanced TreesAdvanced Trees
Advanced Trees
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 

Similar to linked_lists4 (20)

[Queue , linked list , tree]
[Queue , linked list , tree][Queue , linked list , tree]
[Queue , linked list , tree]
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Data Structures
Data StructuresData Structures
Data Structures
 
Double link list
Double link listDouble link list
Double link list
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
Linked list
Linked listLinked list
Linked list
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 
Unit 3 dsa LINKED LIST
Unit 3 dsa LINKED LISTUnit 3 dsa LINKED LIST
Unit 3 dsa LINKED LIST
 
topic11LinkedLists.ppt
topic11LinkedLists.ppttopic11LinkedLists.ppt
topic11LinkedLists.ppt
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Linked List Basics
Linked List BasicsLinked List Basics
Linked List Basics
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
linked list
linked listlinked list
linked list
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
linklisr
linklisrlinklisr
linklisr
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 

More from Mohamed Elsayed (20)

binary_trees4
binary_trees4binary_trees4
binary_trees4
 
binary_trees3
binary_trees3binary_trees3
binary_trees3
 
binary_trees2
binary_trees2binary_trees2
binary_trees2
 
queues
queuesqueues
queues
 
stacks2
stacks2stacks2
stacks2
 
stacks1
stacks1stacks1
stacks1
 
algorithm_analysis2
algorithm_analysis2algorithm_analysis2
algorithm_analysis2
 
algorithm_analysis1
algorithm_analysis1algorithm_analysis1
algorithm_analysis1
 
recursion3
recursion3recursion3
recursion3
 
recursion2
recursion2recursion2
recursion2
 
recursion1
recursion1recursion1
recursion1
 
sorted_listmatch
sorted_listmatchsorted_listmatch
sorted_listmatch
 
binary_search
binary_searchbinary_search
binary_search
 
arrays
arraysarrays
arrays
 
introduction
introductionintroduction
introduction
 
heaps2
heaps2heaps2
heaps2
 
heaps
heapsheaps
heaps
 
hash_tables
hash_tableshash_tables
hash_tables
 
graphs
graphsgraphs
graphs
 
quick_sort
quick_sortquick_sort
quick_sort
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

linked_lists4

  • 1. College of Computing & Information Technology King Abdulaziz University CPCS-204 – Data Structures I Link Lists Gone Wild: Circular and Doubly Linked Lists
  • 2. Linked Lists Gone Wild: Doubly-Linked Lists page 2 © Dr. Jonathan (Yahya) Cazalas Double-Linked Lists  Limitations of a singly-linked list include:  Insertion at the front is O(1)  insertion at other positions is O(n)  Insertion is convenient only after a referenced node  Removing a node requires a reference to the previous node  We can traverse the list only in the forward direction  We can overcome these limitations:  Add a reference in each node to the previous node, creating a double-linked list
  • 3. Linked Lists Gone Wild: Doubly-Linked Lists page 3 © Dr. Jonathan (Yahya) Cazalas Double-Linked Lists (cont.)
  • 4. Linked Lists Gone Wild: Doubly-Linked Lists page 4 © Dr. Jonathan (Yahya) Cazalas Linked Lists  Here’s a doubly linked list node class: public class DLLnode { public int data; public dll_node next; public dll_node prev; // Constructor 1 public DLLnode(int i) { this(i, null, null); } // Constructor 2 public DLLnode(int i, dll_node n, dll_node p) { data = i; next = n; prev = p; } } Each ll_node object has at least 3 fields: (1) data field, which stores information (2) next field, which is used to link the nodes together (3) previous, which links to previous node
  • 5. Linked Lists Gone Wild: Doubly-Linked Lists page 5 © Dr. Jonathan (Yahya) Cazalas Inserting into a Double-Linked List next = = prev data = "Harry" DLLnode next = null = prev data = "Sam" DLLnode next = = prev data = "Sharon" DLLnode DLLnode newNode= new DLLnode("Sharon"); newNode.next = helpPtr; newNode.prev = helpPtr.prev; helpPtr.prev.next = newNode; helpPtr.prev = newNode; from predecessor to predecessor helpPtr newNode
  • 6. Linked Lists Gone Wild: Doubly-Linked Lists page 6 © Dr. Jonathan (Yahya) Cazalas Removing from a Double-Linked List next = = prev data = "Bob" Node next = = prev data = "Harry" Node next = = prev data = "Sharon" Node helpPtr helpPtr.prev.next = helpPtr.next; helpPtr.next.prev = helpPtr.prev;
  • 7. Linked Lists Gone Wild: Doubly-Linked Lists page 7 © Dr. Jonathan (Yahya) Cazalas A Double-Linked List Class So far we have worked only with internal nodes As with the single-linked class, it is best to access the internal nodes with a double-linked list object A double-linked list object has data fields:  head (a reference to the first list Node)  tail (a reference to the last list Node) Insertion at either end is O(1) insertion elsewhere is still O(n)
  • 8. Linked Lists Gone Wild: Doubly-Linked Lists page 8 © Dr. Jonathan (Yahya) Cazalas Circular Lists  Circular double-linked list:  Link last node to the first node, and  Link first node to the last node  We can also build singly-linked circular lists:  Traverse in forward direction only  Advantages:  Continue to traverse even after passing the first or last node  Visit all elements from any starting point  Never fall off the end of a list  Disadvantage: Code must avoid an infinite loop!
  • 9. Linked Lists Gone Wild: Doubly-Linked Lists page 9 © Dr. Jonathan (Yahya) Cazalas Circular Lists (cont.)
  • 10. Linked Lists Gone Wild: Doubly-Linked Lists page 10 © Dr. Jonathan (Yahya) Cazalas Linked Lists Gone Wild ISN’T THAT GREAT ( )! That we are finished with Linked Lists!
  • 11. Linked Lists Gone Wild: Doubly-Linked Lists page 11 © Dr. Jonathan (Yahya) Cazalas Daily Demotivator
  • 12. College of Computing & Information Technology King Abdulaziz University CPCS-204 – Data Structures I Link Lists Gone Wild: Circular and Doubly Linked Lists