write a program that implements a variant of a linked list. This variant has a dummy node pointed to by the head link as
write a program that implements a variant of a linked list. This variant has a dummy node pointed to by the head link as shown in the following figure: Linked list with a dummy first node: item next item next item next head size = 2 -3 17 This trick will allow your code to be a little simpler, not requiring a special case for add or remove operations at index 0. Your constructor method will be: public LinkedList(X head = new Node(null); size = 0; You need to write a class called Linkedlist that implements the following List interface: // a list interface public interface List { public boolean isEmpty(); // returns true if the list is empty, false otherwise public int size(); // returns the number of items in the list public void add(Object item); // adds an item to the list // precondition: none // postcondition: item is added at the end of the list public void add (int index, Object item); // adds an item to the list at the given index // precondition: none // postcondition: item is added at the given index; // the indices of following items are increased by 1. public void remove(int index); // removes the item from the list that has the given index // precondition: none // postcondition: removes the first item in the list whose equl method // matches that of the given item public void remove (Object item); // removes an item from the list // precondition: none // postcondition: removes the first item in the list whose equal method // matches that of the given item; the indices of the following items are // decreased by 1 public List duplicate(); // creates a duplicate of the list // precondition: none // postcondition: returns a copy of the linked list public List duplicateReversed (); // creates a duplicate of the list with the nodes in reverse order // precondition: none // postcondition: returns a copy of the linked list with the nodes in // reverse order In addition to the interface, your LinkedList class needs to implement a toString() method that prints the list in the format In addition to the interface, your LinkedList class needs to implement a toString() method that prints the list in the format [ size: the size_of_the list item1, item2, .... ] Specifications, notes, and hints Your program needs to meet the following specifications: Submit the file LinkedList.java. Your Node class should be an inner class within the LinkedList class. Make sure your class implements the interface as specified, i.e. your class should begin with public class LinkedList implements List. None of your methods should contain a test for the index being equal to 0, as the point is to have a simpler implementation. When commenting your code use Javadoc style comments at the beginning of each method. Put comments at the top of the file with your name, EID, email address, date and course, and a short (one or two line) description of what the program does. We will be testing the code on the machines in the CS computer lab, so make sure your code runs on those machines. Submit your source code files via the checkin program by the due date (read the course syllabus for the late policy).
Step by Step Solution
3.51 Rating (144 Votes )
There are 3 Steps involved in it
Step: 1
code in java interface List public boolean isEmpty returns true if list is empty false otherwise public int size returns the number of items in the list public void addObject item adds an item in the ...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started