package linklist; public class IntDLList { private IntDLLNode head, tail; public IntDLList() { head = tail = null; } public boolean isEmpty() { return head == null; } public void setToNull() { head = tail = null; } public int headData() { if (!isEmpty()) return head.data; else return 0; } public void addToHead(int el) { if (!isEmpty()) { head = new IntDLLNode(el,head,null); head.next.prev = head; } else head = tail = new IntDLLNode(el); } public void addToTail(int el) { if (!isEmpty()) { tail = new IntDLLNode(el,null,tail); tail.prev.next = tail; } else head = tail = new IntDLLNode(el); } public void deleteFromHead() { if (!isEmpty()) { // if at least one node in the list; if (head == tail) // if only one node in the list; head = tail = null; else { // if more than one node in the list; head = head.next; head.prev = null; } } } public void deleteFromTail() { if (!isEmpty()) { if (head == tail) // if only one node on the list; head = tail = null; else { // if more than one node in the list; tail = tail.prev; tail.next = null; } } } public void printAll() { //OutputStream Out) { for (IntDLLNode tmp = head; tmp != null; tmp = tmp.next) System.out.print(tmp.data + " "); } public int find(int el) { IntDLLNode tmp; for (tmp = head; tmp != null && tmp.data != el; tmp = tmp.next); if (tmp == null) return 0; else return tmp.data; } }