Delete node in Doubly Linked List || gfg potd today || 30th june ||easy
ฝัง
- เผยแพร่เมื่อ 29 มิ.ย. 2024
- time complexity -[O(n) for traversing to the position to be deleted ]
space complexity- [O(1) no extra data structure is used]
** check comments for code
#coding #gfg #dailychallenge #gfg #potd #gfgpotd #gfgpotdtoday
Node* deleteNode(Node* head, int x) {
// Your code here
struct Node *temp=head;
struct Node *first=head;
int i=1;
//deleting the first node
if(x==1){
head=head->next;
}
//deleting the exact node given in ques
else{
while(iprev;
first->next=temp->next;
break;
}
else{
temp=temp->next;
i++;
}
}
}
return head;
}