Skip to content

Commit

Permalink
Merge pull request fineanmol#3590 from TechShivam02/patch-2
Browse files Browse the repository at this point in the history
Delete Node From llist
  • Loading branch information
fineanmol authored Oct 13, 2022
2 parents 9728a9a + f279de0 commit 38e46cb
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

Node* deleteNode(Node *head, int pos)
{

if(pos == 1){
Node* temp = head;
head = head->next;

delete temp;

return head;
}

Node* temp= head;
pos = pos-1;


while(pos--){
temp = temp->next;
}


if(temp->next == NULL){
Node* copy = temp;
temp->prev->next = NULL;
delete copy;

return head;
}


Node* copy = temp;

temp->next->prev = temp->prev;
temp->prev->next = temp->next;

delete copy;

return head;





}

0 comments on commit 38e46cb

Please sign in to comment.