- Write a Java Class to Implement a Generic LinkedList
Your list must be implemented as asingly–linked list of generic nodes,where each Node object has two instance variables: an object of the“type variable” class, and a pointer to the next node on thelist.
Your class will contain separatemethods to handle each of the operations read from a data file (seeII., below)
Your class will also overridetoString() to return the objects on the list in the orderin which they occur.
- Write a Test Class for Your LinkedListClass
Your main method will readlist operation instructions from a data file until end-of-file andcall the appropriate method to execute each one.
After each operation is executed,print out the operation and the updated list.
The data file to be used is on theclass web site and the operations are:
- APPEND X – Append object X to the end of thelist
- ADD N X – Insert object X as the new Nthelement in the list, increasing the size of the list by 1
E.g. Suppose the list is:
head-> 1 -> 2 -> 3 -> 4 ->null
After ADD 3 7 itwould be:
head-> 1 -> 2 -> 7 -> 3 -> 4-> null
- DELETE N – Remove the Nth object from thelist
- SWAP M N – Interchange the positions of theMth and Nth objects on the list
For credit, the two nodes mustactually “trade places” in the list, and not merely swap their datavalues
- REVERSE – Reverse the order of the objects onthe list
This must be done by reversing theorder of the nodes themselves, rather than by swapping the datastored
To get credit for yourreverse() method, it must use either one of these 2algorithms:
- For each node on the list except the current “head” node,delete the node and insert it as the newhead
- Use your swap() method
6. CLEAR – Clear thelist (make it empty)
No credit will be given for programs that use anyadditional data structures – either from the Java API or programmerdefined -, other than your own LinkedList class
- It is not necessary to create aniterator for your list
An iterator allows the user of acollection to access each object stored without having to knowanything about how the collection is implemented. For thisassignment, the client does not require that capability.
Answer to Write a Java Class to Implement a Generic Linked List Your list must be implemented as a singly-linked list of generic …