Question
Java Assignment1: Implementing a doubly Linked list The doubly linked list allows backward as well as forward traverse through the list. Each node has two
Java Assignment1: Implementing a doubly Linked list
The doubly linked list allows backward as well as forward traverse through the list. Each node has two references to other nodes instead of one. The first is to the next node, as in ordinary lists. The second is to the previous node as depicted by the figure below.
What to Do?
Implement the MyDLinkedList class as depicted by the figure below.
Programming language: JAVA
- The class should implement the MyList
interface (all abstract methods defined in MyList should be implemented in MyDLinkedList ) and should contain three constructors to create an empty list, create a list from an array of objects or create a list from a List (the list could be an ArrayList or a LinkedList).
- Define and implement all methods in MyDLinkedList. The addAll and removeAll methods are described below:
boolean addAll(List otherList)
Appends all of the elements in the otherList to the end of this list. The method returns true if this list changed as a result of the call.
boolean addAll(int index, List otherList)
Inserts all of the elements in the specified list into this list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The method returns true if this list changed as a result of the call.
Parameters: index - index at which to insert the first element from the specified collection
otherList - list containing elements to be added to this list
boolean removeAll(E target, int index1, int index2)
removes all elements from the list that are equal to target that are held in between index1 and index2. The removeAll method is not well specified. Carefully define your detailed vision for removeAll including preconditions and exceptions that will be thrown.
- Write a test program that creates Three MyDLinkedList instances, list1, list2 and list3 and show that the three constructors and all methods implemented in MyDLinkedList class are working properly.
To Submit:
1. All classes and interface code in one file.
2. The code must be commented.
Thanks!
head next prev next next next - Null tail prev prev Null+ prev > MylistStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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