Download - Linked lists by ammara siddiqui
![Page 1: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/1.jpg)
Linked Lists
![Page 2: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/2.jpg)
Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion
![Page 3: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/3.jpg)
Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion
![Page 4: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/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 by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/5.jpg)
A linked list is a series of connected nodes (or links) where each node is a data structure.
Dynamically allocated data structures can be linked together to form a chain.
A linked list can grow or shrink in size as the program runs.This is possible because the nodes in a linked list are
dynamically allocated.
Defination:
![Page 6: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/6.jpg)
Introduction Definitions
Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists
Advantages
![Page 7: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/7.jpg)
Lists and arraysLists:
![Page 8: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/8.jpg)
Lists and arraysArrays: {Size of the following array is = 4}
Index 0 1 2 3
Value 44 5 96 3
![Page 9: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/9.jpg)
Introduction Definitions
Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists
Advantages
![Page 10: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/10.jpg)
Nodes and pointers
![Page 11: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/11.jpg)
Introduction Definitions
Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists
Advantages
![Page 12: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/12.jpg)
Single linked lists
![Page 13: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/13.jpg)
Introduction Definitions
Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists
Advantages
![Page 14: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/14.jpg)
Double Linked Lists
![Page 15: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/15.jpg)
Introduction Definitions
Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists
Advantages
![Page 16: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/16.jpg)
Circular Lists
![Page 17: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/17.jpg)
Introduction Definitions
Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists
Advantages
![Page 18: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/18.jpg)
Advantages Linked lists are more complex to code and manage than arrays, but
they have some distinct advantages.
a) A linked list can easily grow and shrink in size -◦ The programmer doesn’t need to know how many
nodes will be in the list. They are created in memory as needed.b)Speed of insertion or deletion from the list -◦ Inserting and deleting elements into and out of arrays
requires moving elements of the array. When a node is inserted, or deleted from a linked list, none of the other nodes have to be moved .
![Page 19: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/19.jpg)
Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion
![Page 20: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/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 by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/21.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 22: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/22.jpg)
Insertion at the topSteps: Create a Node Set the node data Values Connect the pointers
![Page 23: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/23.jpg)
Insertion Description
Follow the previous steps and we get
48 17 142head //
head 93
Step 1 Step 2
Step 3
![Page 24: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/24.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 25: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/25.jpg)
Insertion at the endSteps: Create a Node Set the node data Values Connect the pointers
![Page 26: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/26.jpg)
Insertion Description
Follow the previous steps and we get
48 17 142head //
Step 1 Step 2
Step 3
![Page 27: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/27.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 28: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/28.jpg)
Insertion in the middleSteps: Create a Node Set the node data Values Break pointer connection Re-connect the pointers
![Page 29: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/29.jpg)
Insertion DescriptionStep 1 Step 2
Step 3
Step 4
![Page 30: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/30.jpg)
Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion
![Page 31: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/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 by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/32.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 33: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/33.jpg)
Deleting from the topSteps Break the pointer connection Re-connect the nodes Delete the node
![Page 34: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/34.jpg)
Deletion Description
4 17
head
426
4 17
head
426
4 17
head
42
![Page 35: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/35.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 36: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/36.jpg)
Deleting from the endSteps Break the pointer connection Set previous node pointer to NULL Delete the node
![Page 37: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/37.jpg)
Deletion Description
4 17
head
426
4 17
head
426
4 176
head
![Page 38: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/38.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 39: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/39.jpg)
Deleting from the MiddleSteps Set previous Node pointer to next node Break Node pointer connection Delete the node
![Page 40: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/40.jpg)
Deletion Description
4 17 42
head
4 17
head
42
4
head
42
![Page 41: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/41.jpg)
Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion
![Page 42: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/42.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 43: Linked lists by ammara siddiqui](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580d9add8b42a03198b4cf3/html5/thumbnails/43.jpg)
Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion