Question: Please use Java. Consider the following code: public class LinkedListDemo { public static void main(String[] args) { Node list = new Node(Salim); list.next = new

Please use Java.

Consider the following code:

public class LinkedListDemo {

public static void main(String[] args) {

Node list = new Node("Salim");

list.next = new Node("Alice");

Node p = list.next;

list.next = new Node("Bobby", p);

list = new Node("Vien", list);

}

}

class Node

{

String value;

Node next;

Node(String val, Node n)

{

value = val;

next = n;

}

Node(String val)

{

value = val;

next = null;

}

}

1. Draw a diagram showing the nodes in this list and value stored in each node.

2. Add a piece of code at the end of the main method to display the values stored in the list node from beginning to end. Test your code to verify your answer to question 1 above.

3. Write a method that takes a Node reference parameter and displays all the nodes in the linked list references at by the argument. If the list is empty, it outputs . Remove the code you added in exercise 2 and replace it with a call to the new method.

4. Write a piece of code to remove the node with value Bobby from the list. Use the display method you wrote in exercise 3 to test and debug your code.

5. Write a piece of code to add a new node with value Megan: at the beginning of the list

6. Write a piece of code to add a new node with value Amy after the node with value Alice.

Demo this task by writing code to display the code at end of exercise 6.

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!