0

Can anyone please write a C program to delete all the node placed at even position of the link list (start count from 1)

Input: 12-> 15->18 -> 17 -> 19 -> 20 -> 22 -> NULL Output: 12-> 18 -> 19 -> 22 -> NULL

21st Mar 2020, 6:22 AM
Rohit Negi
Rohit Negi - avatar
2 odpowiedzi
0
Oh i do have tried.. Just a newbee here..
21st Mar 2020, 6:34 AM
Rohit Negi
Rohit Negi - avatar
0
Heres the code void delete_evens(struct Node *&head) { struct Node *temp,*step,*prev ; if (head==NULL) return; while(head!=NULL && head->_data%2==0) { temp = head ; head = head -> _next ; delete temp ; } step=head; while (step!=NULL) { if (step-> _data %2==0) { temp = step ; step = step -> _next ; prev->_next=step; delete temp ; } else { prev=step; step = step -> _next ; } } step=NULL; }
21st Mar 2020, 6:35 AM
Rohit Negi
Rohit Negi - avatar