public class DoublyLinkedList { protected int count; // list size protected Node head; // ref. to first element // The tail element will be accessible as head.previous() // and tail.next will be head public DoublyLinkedList() { // post: generates an empty list head = null; count = 0; } public void addFirst(E value) { // post: value is added to beginning of list if (head == null) { head = new Node(value, null, null); head.setNext(head); head.setPrevious(head); } else { Node newNode = new Node(value, head, head.previous()); head.previous().setNext(newNode); head.setPrevious(newNode); head = newNode; } count++; }