Question: Complete the implementation of the Iterator class that can traverse a list both forwards and backwards. public class Iterator { private LinkedList myList; private LinkedList
Complete the implementation of the Iterator class that can traverse a list both forwards and backwards.
public class Iterator
private LinkedList
public Iterator(LinkedList
// return true if there is a "next" element, otherwise returns false public boolean hasNext() { if (myCurrentNode != null) return true; return false; }
// TO BE IMPLEMENTED /* // return true if there is a "prior" element, otherwise returns false public boolean hasPrior() {
} */
// returns the "next" node (really the current one) and // moves the Iterator forward by one node public T next() { T data = myCurrentNode.getData(); myCurrentNode = myCurrentNode.getNextNode(); return data; }
// TO BE IMPLEMENTED /* // returns the "prior" node (really the current one) and // moves the Iterator backward by one node public T prior() {
}
// Sets this iterator to point to the last Node in the list public void setToEnd() {
} */ }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
