Question: You are provided an implementation singly-linked list and a partially implemented Iterator class. Starting with this implementation, modify it so that it is a doubly-linked
You are provided an implementation singly-linked list and a partially implemented
Iterator class. Starting with this implementation, modify it so that it is a doubly-linked list,
and finish the implementation of a class for an Iterator that can traverse this list both
forwards and backwards
public class LinkedList
Node
public LinkedList() { itsFirstNode = null; itsLastNode = null; size = 0; }
public int size() { return this.size; } public Iterator
// THIS WILL NEED TO BE MODIFIED FOR DOUBLY LINKED LIST public void add(T element) {
Node
if (itsFirstNode == null) { itsFirstNode = node; itsLastNode = node; } else { itsLastNode.setNextNode(node); itsLastNode = node; } size++; }
// THIS WILL NEED TO BE MODIFIED FOR DOUBLY LINKED LIST public void add(T element, int index) { int counter = 0; Node
public T get(int index) { int counter = 0; Node
// TO BE IMPLEMENTED /* // returns true if element is in the list, false if not public boolean contains(T element) {
}
// returns the index of the element if it is in the list, -1 if not found public int indexOf(T element) {
}
// returns an Iterator at the location of the element if it is in the list // returns the null reference if the element is not found public Iterator
} */
public String toString() { String returnVal = ""; Node
class Node
// TO BE IMPLEMENTED /* public Node
} */ public void setNextNode(Node
// TO BE IMPLEMENTED /* public void setPriorNode(Node
} */ public String toString() { return data.toString(); } } // end of Node
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
