/* @(#)IntListNode.java   29 October 2005 */


/**
 * An IntListNode is a pair consisting of the int data item
 * and a reference to a possible successor node.
 */
public class IntListNode
{
    int data;
    
    IntListNode next = null;
    
    
    /**
     * The constructor that builds a node with the given
     * number as its data and no successor node.
     */
    public IntListNode(int number) {
        data = number;
    }
    
    
    /**
     * Returns the data in this node.
     */
    public int getData() {
        return data;
    }
    
    
    /**
     * Returns the successor node to this node or null if
     * this node has no successor node.
     */
    public IntListNode getNext() {
        return next;
    }
    
    
    /**
     * Appends the given number to a new node that is put
     * at the end the chain of nodes starting with this
     * node.
     * 
     * Returns a reference to the new node.
     * 
     * This operation is done in time proportional to
     * the length of the chain of nodes starting with
     * this node.
     */
    public IntListNode append(int number) {
        if (next == null)
            return next = new IntListNode(number);
        else
            return next.append(number);
    }
    
}
