-1

how to delete every 3rd node in a circular linked list? After deleting that node, the node is continued to count from the node and again deleting the 3rd node?
Do u have any ideas?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by sourabhtripathi
0

To move through a linked-list, you will need an iterator. In your case of deleted every third node, simply use a counter which will increment after traversing each node. Delete the current node when your counter reaches the value 3. Then reset your counter to 1 upon iterating to the next node. Keep running this until your desired stopping condition is reached.

-1

thanks for ur reply..

but i cudn't make it to run the program successfully...cud u plz send the code for that portion?

To move through a linked-list, you will need an iterator. In your case of deleted every third node, simply use a counter which will increment after traversing each node. Delete the current node when your counter reaches the value 3. Then reset your counter to 1 upon iterating to the next node. Keep running this until your desired stopping condition is reached.

-1
struct *p;//node pointing to start
struct *q=p;//starting ptr;
for(q->null)
{

for(i=0;i<4;i++)//move by 3
{*q++;
}
for(j=0;j<3;j++)//move by2
{*p++
}
p->next=q->next;
q=null;
q->next=p;
}

Edited by Nick Evan: added code-tags

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.