/** * A node with two links. Useful for a number of data structures. * Note that these are not necessarily used for doubly-linked lists, * so the links are not required to be symmetric. However, most * of the terminology used herein is biased toward doubly-linked lists. * * @author Samuel A. Rebelsky * @version 1.1 of April 2000 */ public class DoublyLinkedNode { // +--------+---------------------------------------- // | Fields | // +--------+ /** * The next element. Set to null when this is the * "last" item (e.g., the last item in a list; the * leaf of a tree). */ protected DoublyLinkedNode next; /** * The previous element. Set to null when this is * the "first" item. */ protected DoublyLinkedNode prev; /** * The contents of this thing. */ protected Object contents; // +--------------+---------------------------------- // | Constructors | // +--------------+ /** * Create a node that contains a particular value. */ public DoublyLinkedNode(Object initialContents) { this.contents = initialContents; this.next = null; this.prev = null; } // DoublyLinkedNode(Object) // +------------+------------------------------------ // | Extractors | // +------------+ /** * Get the contents. */ public Object getContents() { return this.contents; } // getContents() /** * Get the next element. Returns null if there is no * next element. */ public DoublyLinkedNode getNext() { return this.next; } // getNext() /** * Get the previous element. Returns null if there is * no previous element. */ public DoublyLinkedNode getPrev() { return this.prev; } // getPrev() // +-----------+------------------------------------- // | Modifiers | // +-----------+ /** * Set the contents of this node. */ public void setContents(Object newContents) { this.contents = newContents; } // setContents(Object) /** * Set the next element. */ public void setNext(DoublyLinkedNode newNext) { this.next = newNext; } // setNext(Object) /** * Set the previous element. */ public void setPrev(DoublyLinkedNode newPrev) { this.prev = newPrev; } // setPrev(Object) } // class DoublyLinkedNode