public class IntNode { private int data; // (1) private IntNode next; // (2) /* An integer node, to be used in a list of integers (see IntList) (1) contains integer data (2) the next IntNode in the list (or null) */ public IntNode(){ data = -999; next = null; } // // The default constructor, producing an empty IntNode element // public IntNode(int data){ this.data = data; next = null; } // // Another constructor, to produce an IntNode // with just data in it (i.e. no reference a next IntNode) // You might think of this as "end of the line" // public IntNode(int data, IntNode next){ this.data = data; this.next = next; } // // Another constructor, to produce an IntNode // with data in it, and a reference to another IntNode // public void setData(int newData){data = newData;} // // upd8 the data in an IntNode // public void setNext(IntNode newNext){next = newNext;} // // upd8 the reference to the next IntNode // public int getData(){return data;} // // get the data in the IntNode // public IntNode getNext(){return next;} public String toString(){ if (next == null) return data + ""; else return data + "," + next.toString(); } public static void main(String[] args) throws Exception { // incase you want to see how it goes, java IntNode IntNode x = new IntNode(), y = new IntNode(2), z = new IntNode(1,y); System.out.println(x); System.out.println(y); System.out.println(z); } }