/**  
    FILE:           Nodes.java
    AUTHORS:        Cheng, Jeff
    PURPOSE:        A list node, used by class LinkedList
                    and class SkipList.
    LAST CHANGE:    3-22-02
    FUNCTIONS:      Nodes() -----> create an instance with no links
                    getAbove() ---> get the node above
                    getBelow() ---> get the node below
                    getCount() ---> get # of instances created so far
                    getNext() ----> get the node after
                    getPrevious()--> get the node before
                    getValue()----> get the integer value stored
                    insertAbove(x)--> insert a node(x) above
                    setAbove()------> set the node above
                    setBelow()------> set the node below
                    setNext() ------> set the node after
                    setPrevious() --> set the node before
                    setValue() -----> set the integer value inside
    CREDIT:         Adapted from Professor Matloff's
                    Java tutorial, UC Davis.
    COPYRIGHT:      You may use, modify, or distribute my code for 
                    non-commerical use only; you must cite me, Jeff Cheng, 
                    as the source. 
*/

package lists;

public class Nodes{
    private int value;  //  key
    //  links to the nodes around
    private Nodes previous;
    private Nodes next;
    private Nodes above;
    private Nodes below;
    //  how many instances created so far
    private static int count = 0;
    /*  Note: since it is static, it stores the *total* number 
        of instances up to this point. e.g.
        count = the total number of nodes created in *each* 
        and *every* costructor call.
        To get the number of instance created
        for this call only, subtract the number of instance
        created up to the last call. (you'll need a new variable)
        e.g.    Number of instances created this time 
        = this count - count from last time. */

    //  assume all links are dead
    public Nodes(int value){ 
        setPrevious(null);
        setNext(null);
        setAbove(null);
        setBelow(null);
        setValue(value);
        //  one more Nodes instance created
        count++;}
 
    //  accessors and mutators
    public static int getCount(){return count;}
    public int getValue(){return value;}
    public void setValue(int value){
        this.value = value;}
    public Nodes getPrevious(){return previous;} 
    public void setPrevious(Nodes previousNode){
        previous = previousNode;}
    public Nodes getNext(){return next;}
    public void setNext(Nodes nextNode){
        next = nextNode;}
    public Nodes getAbove(){return above;}
    public void setAbove(Nodes aboveNode){
        above = aboveNode;}
    public Nodes getBelow(){return below;}
    public void setBelow(Nodes belowNode){
        below = belowNode;}

    //  utility function for class SkipList constructor
    public void insertAbove(int value){
        setAbove(new Nodes(value));
        getAbove().setBelow(this);}
}
