DSA Presentation
DSA Presentation
Lecture 5
Linked lists (continue...)
Basic operation:
Block diagram
P q
Block diagram
P q
NULL
Deleting node.
• p is starting node.
• q in next node.
• In this diagram p is head(starting node). To delete it we have to make q as a head(starting
node).
• Then delete(p).
Deleting a node:End node
Block diagram
P q
NULL
Deleting node.
• To delete end node we use while loop.
• In while loop at beginning, node 1 is head(p) node 2 is next node(q) as the loop
iterate, node 2 become head and node 3 become next node.
• A point reach when second last node is p and last node is q.
Deleting a node:End node
Block diagram
P q
NULL
Deleting node.
A point reach when second last node is p and last node is q.
P q
NULL
Deleting a node:End node
Block diagram
P q
NULL
Deleting node.
To delete end node we have to make p pointing to NULL instead of q.
P q
]
NULL
Deleting a node:End node
Block diagram
P q
NULL
Deleting node.
To delete end node we have to make p pointing to NULL instead of q.
P q
Delete(q)
]
NULL
Deleting a node: Middle node
Block diagram
P q
NULL
Deleting node.
• To delete a middle node we use while loop.
• When q reached to deleting node and p is pointer pointing to node before
deleting node.
Deleting a node: Middle node
Block diagram
P q
NULL
deleting node.
Condition(p point next == q point next)
p q
NULL
delete(q)
Pseudo code: Starting node
Step 1:
Design a method to delete a node
Deleting Node: First node
Step 1:
Design a method to delete a node
Deleting Node: First node
Step 2:
Design other function to insert and display linked list.
Deleting Node: First node
Step 2:
Design other function to insert and display linked list.
Deleting Node: First node
Step 2:
Design other function to insert and display linked list.
Deleting Node: First node
Step 3:
Main() function.
Deleting Node: End node