GeeksforGeeks » Linked List specific questions
deletion from circular linked list
(6 posts)-
You are given a circular single linked list of sufficiently many number of nodes(say more than 1 crore). You need to delete a node say P and you are given a pointer to P in the circular single list. Suggest the most efficient methodology of deleting the node P from the circular single linked list.
-
Copy the data of next node into this and remove the next node.
p.data = p.next.data; Node deletedNode = p.next; p.next = p.next.next; free(deletedNode) -
mdasif .....what if p is the last node
-
only take two condition :-
1st if p is head node
2nd if p is last node
else for other it'll go simple deletion. -
If p is head node it wont make a difference but if p is the last node it will make a difference.
this code will work
q=p->next; p->info=q->info; p->next=q->next; free(q); q=NULL; If(p->next=header) { header=p; } -
nice
Reply
You must log in to post.