Question: Given the following class for the nodes in a linked list: public class Node { public void putNext(Node n) {...} // change next field to

Given the following class for the nodes in a linked list: public class Node { public void putNext(Node n) {...} // change next field to n public Node getNext() {...} // return next public int getData() {...} // returns } Assuming that the variable head points to the first node of a linked list, write the statements to find the first occurrence of the data value m in the linked list and insert n before it. For example, insertBefore (4, 3) would find the first occurrence of 4 and insert 3 before it, then return "insert before 4 3 done", Or "4 not Found" if 4 is not in the list. Your statements will be inserted inside a method like the following: public String insertBefore (int m, int n) { } 

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!