Is the code of deletion in the middle correct or not?
Linked List- Deletion
hey @Rishab, make these changes in function for deleteAtMiddle
else
{
int jumps=1;
node* temp=head,prev=NULL;
while(jumps<=p)
{
prev=temp;
temp=temp->next;
jumps+=1;
}
prev->next=temp->next;
delete temp;
}
@Gaurav13998 what am i doing wrong in this?
I am unable to understand.
else
{
int jumps=1;
node* temp=head;
while(jumps<=p-1)
{
temp=temp->next;
jumps+=1;
}
node* temp1=temp->next->next;
delete temp->next;
temp->next=temp1;
}
hey @Gaurav13998, this code will delete the node after p. Try to dry run it on 1->2->3->4->5 with p=3
Ok.
Actually i am assuming starting node as 0;
Got it. Thanks
hey @Rishab , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved