0

Can any1 check if this C fuction to delete all the node placed at even position of the link list (start count from 1) is right?

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; } Input: 12-> 15->18 -> 17 -> 19 -> 20 -> 22 -> NULL Output: 12-> 18 -> 19 -> 22 -> NULL

21st Mar 2020, 6:33 AM
Rohit Negi
Rohit Negi - avatar
1 Resposta
+ 1
Could you please paste this code in a program in this app and share the link to the program? That would be easier to read. Also try to make your question a bit more clear please.
21st Mar 2020, 11:36 AM
AngryBlackSheep
AngryBlackSheep - avatar