Skip to main content

Delete every Kth node from circular linked list

Suppose linked list contain n nodes, and our goal is find and delete every kth position nodes in this linked list.

Test Cases: There are following cases are possible in this problem.

1) When linked list are empty then we cannot deleted any element of this linked list. In this situation try to display a valid message to output screen like (Linked list is empty).

2) Given position is positive integer and that is between of (1 to N). N is number of linked list nodes. If in case gives negative value then display a message like given kth position are not valid.

3) This case are only work when above both condition is not satisfied. In this case we are finding the deleted node position. And delete every kth node. When deleted position value is one then remove all element of given linked list.

Before remove consider this pointe circular linked list last node is connect to first node of linked list. in case deleting last node then if previous node are exist then, this is should be connected to first node.

I am assume you are know about how to find kth node in linked list, If there is not know then we can use one counter variable which are start with 0 and incremented by when iterates linked list nodes. and check kth nodes by (counter%kth position==0).

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

Before Remove kth node After Remove kth node

Here given code implementation process.





Comment

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