0% found this document useful (0 votes)
21 views15 pages

Lecture 10.2 (Update)

Uploaded by

Md Nirjhor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views15 pages

Lecture 10.2 (Update)

Uploaded by

Md Nirjhor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Linked List

Course Code: CSC 2106 Course Title: Data Structure (Theory)

Dept. of Computer Science


Faculty of Science and Technology

Lecturer No: 8.2 Week No: 8 Semester:


Lecturer: Dr. Mohammad Rabiul Islam. Email : [email protected]
Linked List Resources

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

Creating Node Structure

Memory allocation for head

Memory allocation for Current

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

If head is 1000, ptr=head means ptr 1000


ptr → link is 2000
New pointer created lets say 3000 is ptr

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

Head = ptr means


head was 1000, ptr 3000,
after Head = ptr command head becomes 3000
Deleting First Node
Deleting Last Node
Searching for specific Values
Lecture Outline

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

Curr Curr Curr Curr Curr Curr


Linked List
Insertion (Algorithm and simulation)

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,

You might also like