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 : 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 ;
public void addToFrontT item
public void addToBackT item
public void removeint index
public T getint 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 pgetNext
result pgetItem
;
return result.substringresult.length; 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
