mplement Two Way Linked List The MyLinkedList class is a one-way directional linked list that enables one-way traversal of the list. MyLinkedList.java is attached below. Modify the Node class to add the new field named previous to refer to the previous node in the list, as follows: public class Node { E element; Node next; Node previous; public Node(E e) { element = e; } } Implement a new class named MyTwoWayLinkedList that uses a double linked list to store elements. The MyLinkedList class in the text extends MyList. Define MyTwoWayLinkedList to extend the java.util.AbstractSequentialList class. You can find methods of AbstractSequentialList from this article: https://www.geeksforgeeks.org/abstractsequentiallist-in-java-with-examples/. Study MyLinkedList.java carefully to understand how it is structured, and where and what you need to modify/implement for MyTwoWayLinkedList. Since MyTwoWayLinkedList extends java.util.AbstractSequentialList which implements Iterable, it includes an iterator () method that returns an object of the iterator interface automatically. Read the article https://www.softwaretestinghelp.com/java/learn-to-use-java-iterator-with-examples/ for basics to use iterator. In order to iterate through MyTwoWayLinkedList, we need to implement the methods listIterator() and listIterator(int index). Both return an instance of java.util.ListIterator. The former sets the cursor to head of the list and the latter to the element at the specific index. public ListIterator listIterator() { return new TwoWayLinkedListIterator(); } public ListIterator listIterator(int index) { return new TwoWayLinkedListIterator(index); } Here, TwoWayLinkedListIterator is a private class similar to LinkedListIterator in MyLinkedList.java. It defines a custom iterator for TwoWayLinkedList. Make sure to implement methods previous(), previousIndex(), and hasPrevious() similar to next(), nextIndex(), and hasNext() methods in MyLinkedList class. All the methods dealing with add/remove may need to be modified to handle both next and previous fields. Implement a new class named TestMyTwoWayLinkedList to test your two-way linked list with Double as the concert type for the elements in the linked list.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Implement Two Way Linked List

The MyLinkedList class is a one-way directional linked list that enables one-way traversal of the list. MyLinkedList.java is attached below. Modify the Node class to add the new field named previous to refer to the previous node in the list, as follows:

public class Node <E> { E element;

Node<E> next; Node<E> previous;

public Node(E e) { element = e;

} }

Implement a new class named MyTwoWayLinkedList that uses a double linked list to store elements. The MyLinkedList class in the text extends MyList. Define MyTwoWayLinkedList to extend the java.util.AbstractSequentialList class. You can find methods of AbstractSequentialList from this article: https://www.geeksforgeeks.org/abstractsequentiallist-in-java-with-examples/. Study MyLinkedList.java carefully to understand how it is structured, and where and what you need to modify/implement for MyTwoWayLinkedList.

Since MyTwoWayLinkedList extends java.util.AbstractSequentialList which implements Iterable<E>, it includes an iterator () method that returns an object of the iterator interface automatically. Read the article https://www.softwaretestinghelp.com/java/learn-to-use-java-iterator-with-examples/ for basics to use iterator. In order to iterate through MyTwoWayLinkedList, we need to implement the methods listIterator() and listIterator(int index). Both return an instance of java.util.ListIterator<E>. The former sets the cursor to head of the list and the latter to the element at the specific index.

public ListIterator<E> listIterator() { return new TwoWayLinkedListIterator();

}

public ListIterator<E> listIterator(int index) { return new TwoWayLinkedListIterator(index);

}

Here, TwoWayLinkedListIterator is a private class similar to LinkedListIterator in MyLinkedList.java. It defines a custom iterator for TwoWayLinkedList. Make sure to implement methods previous(), previousIndex(), and hasPrevious() similar to next(), nextIndex(), and hasNext() methods in MyLinkedList class.

All the methods dealing with add/remove may need to be modified to handle both next and previous fields.

Implement a new class named TestMyTwoWayLinkedList to test your two-way linked list with Double as the concert type for the elements in the linked list.

 

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY