Delete middle node of a circular single linked list

Delete middle node of circular linked list first need to find the middle nodes. We can find middle node in two ways.

First method: This is simple method first iterates all node of linked list and get the length of linked list, And second iteration loop are execute (length/2) times and get middle node and remove this nodes.

Second method: In this method use two pointer variables, Assign the reference of head nodes to this both pointers. In this case first pointer is slow pointer which are visit next node by one. and second is fast pointer that are visit second next upcoming nodes. This process are repeated when until second pointer next upcoming nodes are not head or not overlap head.

In this situation first node is point to middle node of circular linked list and deleted this nodes.

Test cases: 1) When linked list are empty then display the message of like (linked list is empty).

2) When linked list are less than two nodes in this case we are not delete any nodes.

3) When linked list are contain Even number of nodes then in this case there is possible to have same priorities of the two middle node. In this case delete first node. For example.

Before delete middle node :
 Linked List Element :  1  2  3  4  5  6  7  8
 //two middle node is same priorities (4,5)
After delete middle node :
 Linked List Element :  1  2  3  5  6  7  8
 //Note that deleted first middle node (4) in this case

Suppose we are inserted the following (1,2,3,4,5,6,7) node in a sequence.

Before delete a middle node of circular single linked list After delete a middle node of circular single linked list

Here given code implementation process.



Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved