Question: Task 1 : Linked List and Node Implementation Implement a general linked list class with a parameterized type for the data item. Here is a

Task 1: Linked List and Node Implementation
Implement a general linked list class with a parameterized type for the data item. Here is a start of LinkedList.java:
public class LinkedList {
_____________________ head;
protected int size;
public LinkedList(){
head = null;
size =0;
}
public void addToFront(T item){
.
}
public void addToBack(T item){
.
}
public void remove(int index){
.
}
public T get(int index){
.
}
public void clear(){
.
}
public int size(){
.
}
@Override
public String toString(){
String result ="";
if (head == null)
return result;
for (Node p = head; p != null; p = p.getNext()){
result += p.getItem()+"
";
}
return result.substring(0,result.length()-1); // remove last
}
}
What is the type of head? It must refer to a Node that contains an instance variable to hold a data item of type T and a next value of type Node. Here is the start of Node.java:
Fill in the missing pieces in these two classes, and test them with main method, either in LinkedList.java or in a new file named something like TestLL.java, that looks like this.
Note that you need to implement the Node class that consists of two variables string item and a Node next object.

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!