Can’ t we do just by deleting as deletion done in singly Linked list because situation is almost similar and only difference is that tail->next=head; ??
Circular Linked List Deletion
Case 1 : List is empty.
- If the list is empty we will simply return.
Case 2 :List is not empty
- If the list is not empty then we define two pointers curr and prev and initialize the pointer curr with the head node.
- Traverse the list using curr to find the node to be deleted and before moving curr to next node, everytime set prev = curr.
- If the node is found, check if it is the only node in the list. If yes, set head = NULL and free(curr).
- If the list has more than one node, check if it is the first node of the list. Condition to check this( curr == head). If yes, then move prev until it reaches the last node. After prev reaches the last node, set head = head -> next and prev -> next = head. Delete curr.
- If curr is not first node, we check if it is the last node in the list. Condition to check this is (curr -> next == head).
- If curr is the last node. Set prev -> next = head and delete the node curr by free(curr).
- If the node to be deleted is neither the first node nor the last node, then set prev -> next = temp -> next and delete curr.
But bhiya taught in different way
i gave the reasoning for this stmt
u need to have a modified approach that u would have taken up if it wwas a singly linked list
u can take any of the approach the one taught in gfg or what Sanket bhaiya has taught
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.