Question: Modify the following code so that it is an implementation of a doubly-linked list. public class LinkedList { Node itsFirstNode; Node itsLastNode; private int size;
Modify the following code so that it is an implementation of a doubly-linked list.
public class LinkedList
itsFirstNode = null; itsLastNode = null; size = 0; } 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
