Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Solve the each equation =1+2+3 + + n = k=1

Answered: 1 week ago

Question

Distinguish between hearing and listening.

Answered: 1 week ago

Question

Use your voice effectively.

Answered: 1 week ago