linked lists.ppt
DESCRIPTION
linke listTRANSCRIPT
![Page 1: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/1.jpg)
Linked Lists
Mohammed AlmashatCS 561
26/03/2006
![Page 2: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/2.jpg)
Outline
• Introduction• Insertion Description• Deletion Description• Basic Node Implementation• Conclusion
![Page 3: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/3.jpg)
Outline
• Introduction• Insertion Description• Deletion Description• Basic Node Implementation• Conclusion
![Page 4: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/4.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 5: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/5.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 6: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/6.jpg)
Lists and arrays
• Lists:
![Page 7: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/7.jpg)
Lists and arrays
• Arrays: {Size of the following array is = 4}
Index 0 1 2 3Value 44 5 96 3
![Page 8: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/8.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 9: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/9.jpg)
Nodes and pointers
![Page 10: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/10.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 11: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/11.jpg)
Single linked lists
![Page 12: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/12.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 13: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/13.jpg)
Double Linked Lists
![Page 14: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/14.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 15: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/15.jpg)
Circular Lists
![Page 16: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/16.jpg)
Introduction
• Definitions– Lists and arrays– Nodes and pointers– Single Linked Lists– Double Linked Lists– Circular Lists
• Advantages
![Page 17: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/17.jpg)
AdvantagesThe Linked List advantages are collected because of the
array disadvantages, array disadvantages are:1. Array Size2. Memory allocation3. Insertion and Deletion
![Page 18: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/18.jpg)
Outline
• Introduction• Insertion Description• Deletion Description• Basic Node Implementation• Conclusion
![Page 19: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/19.jpg)
Insertion Description
• Insertion at the top of the list• Insertion at the end of the list• Insertion in the middle of the list
![Page 20: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/20.jpg)
Insertion Description
• Insertion at the top of the list• Insertion at the end of the list• Insertion in the middle of the list
![Page 21: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/21.jpg)
Insertion at the top
Steps:• Create a Node• Set the node data Values• Connect the pointers
![Page 22: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/22.jpg)
Insertion Description
• Follow the previous steps and we get
48 17 142head //
head 93
Step 1 Step 2
Step 3
![Page 23: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/23.jpg)
Insertion Description
• Insertion at the top of the list• Insertion at the end of the list• Insertion in the middle of the list
![Page 24: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/24.jpg)
Insertion at the end
Steps:• Create a Node• Set the node data Values• Connect the pointers
![Page 25: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/25.jpg)
Insertion Description
• Follow the previous steps and we get
48 17 142head //
Step 1 Step 2
Step 3
![Page 26: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/26.jpg)
Insertion Description
• Insertion at the top of the list• Insertion at the end of the list• Insertion in the middle of the list
![Page 27: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/27.jpg)
Insertion in the middle
Steps:• Create a Node• Set the node data Values• Break pointer connection• Re-connect the pointers
![Page 28: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/28.jpg)
Insertion Description
Step 1 Step 2
Step 3
Step 4
![Page 29: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/29.jpg)
Outline
• Introduction• Insertion Description• Deletion Description• Basic Node Implementation• Conclusion
![Page 30: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/30.jpg)
Deletion Description
• Deleting from the top of the list• Deleting from the end of the list• Deleting from the middle of the list
![Page 31: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/31.jpg)
Deletion Description
• Deleting from the top of the list• Deleting from the end of the list• Deleting from the middle of the list
![Page 32: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/32.jpg)
Deleting from the top
Steps• Break the pointer connection• Re-connect the nodes• Delete the node
![Page 33: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/33.jpg)
Deletion Description
4 17
head
426
4 17
head
426
4 17
head
42
![Page 34: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/34.jpg)
Deletion Description
• Deleting from the top of the list• Deleting from the end of the list• Deleting from the middle of the list
![Page 35: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/35.jpg)
Deleting from the end
Steps• Break the pointer connection• Set previous node pointer to NULL• Delete the node
![Page 36: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/36.jpg)
Deletion Description
4 17
head
426
4 17
head
426
4 176
head
![Page 37: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/37.jpg)
Deletion Description
• Deleting from the top of the list• Deleting from the end of the list• Deleting from the middle of the list
![Page 38: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/38.jpg)
Deleting from the Middle
Steps• Set previous Node pointer to next node• Break Node pointer connection• Delete the node
![Page 39: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/39.jpg)
Deletion Description
4 17 42
head
4 17
head
42
4
head
42
![Page 40: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/40.jpg)
Outline
• Introduction• Insertion Description• Deletion Description• Basic Node Implementation• Conclusion
![Page 41: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/41.jpg)
Basic Node ImplementationThe following code is written in C++:
Struct Node{
int data; //any type of data could be another struct
Node *next; //this is an important piece of code “pointer”
};
![Page 42: Linked Lists.ppt](https://reader036.vdocuments.net/reader036/viewer/2022062301/563dbaf4550346aa9aa902f9/html5/thumbnails/42.jpg)
Outline
• Introduction• Insertion Description• Deletion Description• Basic Node Implementation• Conclusion