Question: For this problem, there is a complete linked list program which supports the following commands from the user: insert, display, delete, average, find, insertBefore, insertAfter.

For this problem, there is a complete linked list program which supports the following commands from the user: insert, display, delete, average, find, insertBefore, insertAfter. insert allows them to insert a number into the current list, display will display the numbers in the current list etc. The program is complete except the body for delete has been removed. 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 field public int getData() {...} // returns data } Assuming that the variable head points to (i.e. contains the address of) the first node of a linked list, write the statements to find the first occurrence of the data value x in the linked list and delete it. For example, delete(4) would return something like "deleted 4" or "Not found". Your statements will be inserted inside a method like the following: public String delete(int x) { // Whatever statements you provide in response to this question will // be inserted here BY THE SYSTEM and then compiled and tested as part of // a larger program which does many other things with the linked list }

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!