0% found this document useful (0 votes)
7 views25 pages

DSA Presentation

This lecture focuses on linked lists, specifically on the basic operations of searching, inserting, and deleting nodes. It details the scenarios for deleting nodes from the start, end, and middle of the list, along with block diagrams and pseudo code for implementation. The lecture concludes with a reminder to stay engaged as it wraps up.

Uploaded by

Muneeb
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)
7 views25 pages

DSA Presentation

This lecture focuses on linked lists, specifically on the basic operations of searching, inserting, and deleting nodes. It details the scenarios for deleting nodes from the start, end, and middle of the list, along with block diagrams and pseudo code for implementation. The lecture concludes with a reminder to stay engaged as it wraps up.

Uploaded by

Muneeb
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/ 25

Data structure and algorithm

Lecture 5
Linked lists (continue...)
Basic operation:

Search. the list for an item


Insert. an item in the list
Delete. an item from the list
Basic operation:

Topic to be completed in this lecture.


Search. the list for an item
Insert. an item in the list
Delete. an item from the list
Deleting a node:

To delete a node, there are three possible scenerios:


• Deleting from the start.
• Deleting at the end.
• Deleting from the middle.
Deleting a node:Start point

Block diagram
P q

Let p and q are 2 pointer.


P pointing to current node and q pointing to next node
Deleting a node:Start point

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

Node * delete(node *head, char d){


Node *p,*q;
P=head;
q=next->head;
If(p->data ==d){ //d is deleting node
Head=q;
Delete(p);}
Else
While(q->data!=d)
{q=q->next;
P=p->next;
}
}
Pseudo code: End node and internal node

If(q->data ==NULL){ // deleting last node


P->next=NULL;
Delete(q);}
Else // deleting internal node
{p->next==q->next;
delete(q);
}
Implementation
Deleting Node: First 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

Just modify delete function:


Deleting Node: middle node

Just modify delete function:


Thanks a lot

If you are taking a Nap, wake up........Lecture Over

You might also like