please give me the code of deleting in middle
i cannot get through it at all
Cannot figure out a code
hi varun,
Here is the code and i have added comments also for your better understanding.
void deleteNode(Node *head, int x)
{
//if the linked list is empty
if (head == NULL) return;
Node* temp = head;
//if heads needs to be removed
if (x == 0){
head = temp->next;
return;
}
//got to the position-1 from which you want to delete the node.
for (int i=0; temp!=NULL && i<x-1; i++)
temp = temp->next;
//if we have reached the end or ahead of it.
if (temp == NULL || temp->next == NULL) return;
Node *next = temp->next->next;
temp->next = next;
}
Please let me know if you have any doubt in this code.
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.