Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function to delete all nodes greater than the first nodes\' data in Doub

ID: 3594081 • Letter: W

Question

Write a function to delete all nodes greater than the first nodes' data in Doubly linked list using C++.

Right now my function only removes the next following number that's greater than the first node.

How can I get it to traverse the whole list and remove nodes that are greater than head's data?

36 void delete node (node*&head;, node*&temp;) 37 38 39 40 if (!head &&!temp) return if (headtemp) 42 43 head temp-> next; if (temp->next !=NULL) temp->next->previous temp->previous; 45 4 6 47 48 49 50 51 52 53 54 55 //Remove every item larger than the first item 56 int remove larger (node*&head;) 57 58 59 60 61 62 63 = if (temp->previous!-NULL) temp->previous->next temp->next ; = delete temp; return if (head) return 0 int count =0; node * current = head; while (current !=NULL) current current->next ; 65 if (current ->data >head->data) 67 68 69 70 71 72 73 delete node (head, current); count ++ return count; 75 76 return counti

Explanation / Answer

//Just edit while loop in your function by this code

while (current != NULL) {

/* if node found with the value greater than first node */
if (current->data > head->data) {

/* save current's next node in the pointer 'next' */
next = current->next;

/* delete the node pointed to by 'current' */
deleteNode(head, current);

/* update current */
current = next;
}

/* else simply move to the next node */
else
current = current->next;
}

Try your code by editing the while loop in your function, and tell me its working fine or not. If still you are facing any problem, then tell me, i will post full code for the required result. thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote