Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions