Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Assignment1: Implementing a doubly Linked list The question doesn't need clarification, please follow the directives and don't make it too complicated: The doubly linked

Java Assignment1: Implementing a doubly Linked list

The question doesn't need clarification, please follow the directives and don't make it too complicated:

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.

image text in transcribed

What to Do?

Implement the MyDLinkedList class as depicted by the figure below.

image text in transcribed

Programming language: JAVA

  1. 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).
  1. 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 > Mylist Node next: Node MyDLinkedList ea - tail -Size MyDinkedList) + MyDLinkedList (arr En + MyDLinkedlist (otherlist List) + addFirst(e: E): void + addLast(e: E): void + getFirst(): E +removeFirst(): E +removeLast(): E + addAll(otherList: List): boolean + addAll(int index, otherList: List: boolean + removeAl target, int index1, int index2):bolear

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