Java. Refer to screenshot. There is starter code. I need help with the method. public class LinkedList { Node head; Node tail; protected class Node{ String data; Node next; } public void...


Java. Refer to screenshot. There is starter code. I need help with the method.


public class LinkedList {
Node head;
Node tail;


protected class Node{
String data;
Node next;
}


public void addLast(String s){
//Complete the method here
}


public String toString(){


String result = "";


Node n = head;
while(n != null){
result += n.data + " -> ";
n = n.next;
}


return result;
}




}




//DO NOT MODIFY THIS CLASS
//All work must be done in the LinkedList.java class
import java.util.Scanner;


public class P1 {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int numNames = kb.nextInt();


LinkedList list = new LinkedList();
for (int i = 0; i < numnames="" ;="" i++)="">
list.addLast(kb.next());
System.out.println(list);
}
}
}


In this problem, you will complete the implementation of the addLast method in a slngle linked list. The add last method should add a new node to the end of the linked list<br>Do not modlfy the lst to be doubly Ilnked.<br>Remember that lists can be in two states: empty or with some elements (1 or more)<br>The Pl class will run the test cases by reading inputs from the user and calling the addLast method. It will print the list after each addlast call<br>Example<br>Input<br>Output<br>Jane -><br>Jane -> Mike -><br>Jane -> Mike -> Bob -><br>3 Jane Mike Bob<br>

Extracted text: In this problem, you will complete the implementation of the addLast method in a slngle linked list. The add last method should add a new node to the end of the linked list Do not modlfy the lst to be doubly Ilnked. Remember that lists can be in two states: empty or with some elements (1 or more) The Pl class will run the test cases by reading inputs from the user and calling the addLast method. It will print the list after each addlast call Example Input Output Jane -> Jane -> Mike -> Jane -> Mike -> Bob -> 3 Jane Mike Bob

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here