c++ code for function that take doubly linked list as parameter and deleted all nodes in even position from first to last
/*If you have any query do comment in the comment section else like the solution*/
void deleteNodesAtEvenPosition(node *head) {
if(head == NULL || head->next == NULL) return;
int count = 1;
node *curr = head;
node *tmp;
while(curr != NULL) {
if(count%2 == 0) {
curr->prev->next = curr->next;
curr->next->prev = curr->prev;
tmp = curr;
curr = curr->next;
delete(tmp);
} else {
curr = curr->next;
}
}
}
Get Answers For Free
Most questions answered within 1 hours.