Question: Remove all odd integers from a doubly linked list. My remove function is not working for the case of when 2 odd integers are next

Remove all odd integers from a doubly linked list.

My remove function is not working for the case of when 2 odd integers are next to each other.

How can I fix this?

117 int remove_from(node*&head) 118 { 119 //if head is to be deleted 120 if(!head->previous) 121 { 122 node * temp = head; 123 head = temp -> next; 124 // head -> previous = NULL; 125 delete temp; 126 temp = NULL; 127 return 0; 128 } 129 130 //end of the list 131 if(!head->next ) 132 { 133 node * temp = head; 134 head = temp -> previous; 135 head -> next = NULL; 136 delete temp; 137 temp = NULL; 138 return 0; 139 } 140 else 141 { 142 node * temp = head; 143 temp -> previous -> next = temp -> next; 144 delete temp; 145 temp = NULL; 146 return 0; 147 } 148 149 return 0; 150 }

int remove_odd(node*&head)

208 {

209 if(!head)

210 return 0;

211

212 if(head -> data % 2 ==1)

213 {

214 remove_from(head);

215 }

216

217 return remove_odd(head->next);

218 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!