import java.io.*; import java.util.*; import java.lang.Object; public class BasicList { /*Node creates the model for our list items * each node has an integer value which is our data * and another Node which is a copy the next item in the list * which also contains an integer and a Node object of next... */ class Node{ int data; Node next = null; } private Node startOfList = null;//initialized the first item to empty, the empty list /* *addTo is the method for inserting items in the list *it takes an integer from main, calls Node to create a new *instance of Node and sets the new item to the head of the list, *pushing the previous item down. That item may be null in which *case, null now indicates the end of our list and it is how we *can determine that we are at the end. */ public void addTo(int data){ Node newNode = new Node(); newNode.data = data; newNode.next = startOfList; startOfList = newNode; } /* *printList() displays the contents of our list in order *by checking if the next item is null, if not it keeps going. * */ public void printList(){ Node current = startOfList; while(current != null){ System.out.print(current.data); current = current.next; } System.out.println(); } //end methods public static void main(String args[]) throws Exception { BasicList list = new BasicList(); list.addTo(3); list.addTo(5); list.addTo(9); list.printList(); }//end main }//end class