0% found this document useful (0 votes)
354 views2 pages

C Program To Delete Middle Node of Singly Linked List: Required Knowledge

The document describes how to delete the middle node of a singly linked list in C. It provides an algorithm that iterates through the list to find the middle node, keeps track of the node before it, and then reconnects the previous node to the node after the one to be deleted. It also gives the steps: 1) traverse to the nth node and keep track of the previous node, 2) reconnect the previous node to the next node, and 3) free the memory of the deleted node. The algorithm and steps allow deleting the middle node from a singly linked list in C.

Uploaded by

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

C Program To Delete Middle Node of Singly Linked List: Required Knowledge

The document describes how to delete the middle node of a singly linked list in C. It provides an algorithm that iterates through the list to find the middle node, keeps track of the node before it, and then reconnects the previous node to the node after the one to be deleted. It also gives the steps: 1) traverse to the nth node and keep track of the previous node, 2) reconnect the previous node to the next node, and 3) free the memory of the deleted node. The algorithm and steps allow deleting the middle node from a singly linked list in C.

Uploaded by

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

3/13/2019 C program to delete middle node of Singly Linked List - Codeforwin

Learn C programming, Data Structures tutorials, exercises, examples, programs, hacks, tips and tricks online. A blog for beginners
to advance their skills in programming.

C program to delete middle node of Singly


Linked List
September 25, 2015 Pankaj Data Structures C, Data Structures, Linked List, Program,
Singly Linked List

Write a C program to create a singly linked list of n nodes and delete node from the middle of the linked list.
How to delete node from the middle of the singly linked list in C. Algorithm to delete middle node from singly
linked list. Steps to delete middle node from singly linked list.

Required knowledge
Basic C programming, Functions, Singly linked list, Dynamic memory allocation

Algorithm to delete middle node of Singly


Linked List

Algorithm to delete middle node of Singly Linked List


%%Input : head node of the linked list
n node to be deleted
Begin:
If (head == NULL) then
write ('List is already empty')
End if
Else then
toDelete ← head
prevNode ← head
For i←2 to n do
prevNode ← toDelete
toDelete ← toDelete.next
If (toDelete == NULL) then
break
https://codeforwin.org/2015/09/c-program-to-delete-middle-node-of-singly-linked-list.html 1/5
3/13/2019 C program to delete middle node of Singly Linked List - Codeforwin

End if
End for
If (toDelete != NULL) then
If (toDelete == head) then
head ← head.next
End if
prevNode.next ← toDelete.next
toDelete.next ← NULL
unalloc (toDelete)
End if
End else
End

Steps to delete middle node of Singly Linked


List
1. Traverse to the nth node of the singly linked list and also keep reference of n-1th node in some
temp variable say prevnode .

2. Reconnect the n-1th node with the n+1th node i.e. prevNode->next = toDelete->next
(Where prevNode is n-1th node and toDelete node is the nth node and toDelete->next
is the n+1th node).

3. Free the memory occupied by the nth node i.e. toDelete node.

https://codeforwin.org/2015/09/c-program-to-delete-middle-node-of-singly-linked-list.html 2/5

You might also like