public E get(int i) { MyLinkedNode<E> currentNode = head; E value = null; for (int j = 0; j <= i + 1; j++) { value = currentNode.getValue(); currentNode = currentNode.getNext(); } return value; }
public void clear() { // set head's next to the tail head.setNext(tail); head.setPrev(null); // set tails prev to the head tail.setPrev(head); tail.setNext(null); numElements = 0; }
public void add(E s) { MyLinkedNode<E> newNext = tail; MyLinkedNode<E> newPrev = tail.getPrev(); MyLinkedNode<E> newNode = new MyLinkedNode<E>(s); newNext.setPrev(newNode); newNode.setPrev(newPrev); newPrev.setNext(newNode); newNode.setNext(newNext); numElements++; }
public void add(int i, E s) { MyLinkedNode<E> prevNode = head; MyLinkedNode<E> newNode = new MyLinkedNode<E>(s); for (int j = 0; j <= i + 1; j++) { prevNode = prevNode.getNext(); } MyLinkedNode<E> nextNode = prevNode.getNext(); newNode.setPrev(prevNode); newNode.setNext(nextNode); nextNode.setPrev(newNode); numElements++; }