Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3) (Review linked list) The MyLinkedList class used in Listing 24.1 below in the references section) is a one-way directional linked list that enables one-way
3) (Review linked list) The MyLinkedList class used in Listing 24.1 below in the references section) is a one-way directional linked list that enables one-way traversal of the list. Modify the Node class to add the new data field name 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 TwoWayLinkedList that uses a doubly linked list to store elements. The MyLinkedList class in the text extends MyAbstractList. Define TwoWayLinked List to extend the java.util.AbstractSequentialList class. You need to implement all the methods defined in MyLinkedList as well as the methods listIterator and listIterator(int index). Both return an instance of java.util.ListIterator. The former sets the cursor to the head of the list and the latter to the element at the specified index. References LISTING 24.1 MyList.java 1 public interface MyList extends java.lang. Iterable { 2 /** Add a new element at the end of this list */ 3 public void add (2 e); 5 /** Add a new element at the specified index in this list */ 6 public void add (int index, Ee); 8 9 / +- Clear the list */ public void clear(); /** Return true if this list contains the element */ public boolean contains (E e); 12 /** Return the element from this list at the specified index */ public E get (int index); /** Return the index of the first matching element in this list. + Return -1 if no match. */ public int indexOf(Ee); /** Return true if this list doesn't contain any elements */ public boolean isEmpty(); /** Return the index of the last matching element in this list + Return -1 if no match. */ public int lastIndexOf(E e); /** Remove the first occurrence of the element e from this list. + Shift any subsequent elements to the left. + Return true if the element is removed. */ 31 public boolean remove (E e); /** Remove the element at the specified position in this list. + Shift any subsequent elements to the left. + Return the element that was removed from the list. / 36 public E remove(int index); /** Replace the element at the specified position in this list * with the specified element and return the old element. */ 40 public Object set (int index, Ee); 41 42 /** Return the number of elements in this list */ 43 public int size(); 44 ) 3) (Review linked list) The MyLinkedList class used in Listing 24.1 below in the references section) is a one-way directional linked list that enables one-way traversal of the list. Modify the Node class to add the new data field name 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 TwoWayLinkedList that uses a doubly linked list to store elements. The MyLinkedList class in the text extends MyAbstractList. Define TwoWayLinked List to extend the java.util.AbstractSequentialList class. You need to implement all the methods defined in MyLinkedList as well as the methods listIterator and listIterator(int index). Both return an instance of java.util.ListIterator. The former sets the cursor to the head of the list and the latter to the element at the specified index. References LISTING 24.1 MyList.java 1 public interface MyList extends java.lang. Iterable { 2 /** Add a new element at the end of this list */ 3 public void add (2 e); 5 /** Add a new element at the specified index in this list */ 6 public void add (int index, Ee); 8 9 / +- Clear the list */ public void clear(); /** Return true if this list contains the element */ public boolean contains (E e); 12 /** Return the element from this list at the specified index */ public E get (int index); /** Return the index of the first matching element in this list. + Return -1 if no match. */ public int indexOf(Ee); /** Return true if this list doesn't contain any elements */ public boolean isEmpty(); /** Return the index of the last matching element in this list + Return -1 if no match. */ public int lastIndexOf(E e); /** Remove the first occurrence of the element e from this list. + Shift any subsequent elements to the left. + Return true if the element is removed. */ 31 public boolean remove (E e); /** Remove the element at the specified position in this list. + Shift any subsequent elements to the left. + Return the element that was removed from the list. / 36 public E remove(int index); /** Replace the element at the specified position in this list * with the specified element and return the old element. */ 40 public Object set (int index, Ee); 41 42 /** Return the number of elements in this list */ 43 public int size(); 44 )
Step 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