Question: The program is complete except that I have removed the body of the method for delete. 1. Given the following class for the nodes in
The program is complete except that I have removed the body of the method for delete. 1. 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 } 2.
method for insertBefore
Given the following class for the nodes in a linked list: public class Node { ... Node (int x, Node n) {...} // constructor for creating nodes with data i.e. x and next i.e. n field values public void putNext(Node n) // for updating the next (pointer) field in the node 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 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) { // 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
