Skip to content

Commit

Permalink
Delete Node From llist
Browse files Browse the repository at this point in the history
Gfg || Important || Interview Problem || Optimized
  • Loading branch information
TechShivam02 authored Oct 13, 2022
1 parent 55e6c42 commit f279de0
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 f279de0

Please sign in to comment.