Lecture 10.2 (Update)
Lecture 10.2 (Update)
Intro: https://www.youtube.com/watch?
v=R9PTBwOzceo&list=PLBlnK6fEyqRi3-lvwLGzcaquOs5OBTCww
Single link list: https://www.youtube.com/watch?
v=b5QR4AmrspU&list=PLBlnK6fEyqRi3-lvwLGzcaquOs5OBTCww&index=2
Traversing: https://www.youtube.com/watch?v=e0s-
zmpedYo&list=PLBlnK6fEyqRi3-lvwLGzcaquOs5OBTCww&index=6
Creating Link list Nodes
Head created first, then again another node created, but replacing first one (bcz both of them are
Head means the starting memory address in this scenario it is 1000
Data assigned
At first link is assigned null
head was 1000, and ptr null,
Now, head assigned to ptr link, means
Ptr→ link is 1000 not null anymore
1. Linked List
• Search
• Insertion
• Deletion
Linked List
Searching (Algorithm and simulation)
Algorithm
Input: Head (the address of first node)
Curr = Head
Step 1: if Curr == NULL print not found and exit
If Curr->data = item print found and exit
Step 2: move Curr to next node and go to step 1 Item = 15
Item = 5 Not Found!
Found!
Head
12 3 14 5 16 NULL
Algorithm
Head Node
Input:
Head (the address of first node),
Node (inserting node), Node->next
Prev (address of previous node)
Case 1:
if Prev != NULL then go to Case 2
Make a link from Node to first node Prev->next
Prev
Make Node as the Head
Exit
Case 1: 2: Inserting at
after a given node
Head
Case 2:
Make a link from Node to the node next to Prev
Make another link from Prev to Node
Linked List
Deletion (Algorithm and simulation)
Algorithm
Input: Prev->next
Curr->next Curr->next
Head (the address of first node), Head
Prev (address of previous node)
Case 1:
if Prev = NULL then go to Case 2 Curr Prev Curr
Curr = Prev->next
Make a link from Prev to the node next to Curr
Exit Case 1:
2: Delete the
afterfirst nodenode
a given
Case 2:
Make the node next to Head as new Head
References
1. https://en.wikipedia.org/wiki/Linked_list
Books
“Schaum's Outline of Data Structures with C++”. By John R. Hubbard
“Data Structures and Program Design”, Robert L. Kruse, 3rd Edition, 1996.
“Data structures, algorithms and performance”, D. Wood, Addison-Wesley, 1993
“Advanced Data Structures”, Peter Brass, Cambridge University Press, 2008
“Data Structures and Algorithm Analysis”, Edition 3.2 (C++ Version), Clifford A.
Shaffer, Virginia Tech, Blacksburg, VA 24061 January 2, 2012
“C++ Data Structures”, Nell Dale and David Teague, Jones and Bartlett Publishers,
2001.
“Data Structures and Algorithms with Object-Oriented Design Patterns in C++”,
Bruno R. Preiss,