public class LLexample2 {

// Ignore args
public static void main(String[] args)
{
LinearNode<Integer> head,ptr;

// Insert at the beginning of the linked list
// Create 1st node using second constructor with
// one actual parameter
// Make node.next --> null and node.element --> 10
// Result in the end: head --> 1 --> 2 --> .... 9 --> 10
LinearNode<Integer> node=new LinearNode<Integer>(10);

// Make head point to that node
head=node;
for(int i=9;i>=1;i--)
{
// Create new LinearNode object with element i
// Note: LinearNode<Integer> node=new LinearNode<Integer>(i);
// won't work here as you would be redeclaring node!!!
// Remove the LinearNode<Integer> and the node variable
// can be made to point to other nodes.
node=new LinearNode<Integer>(i);

// Make the next pointer of that node to the head of
// the current linked list
node.setNext(head);

// Make the new head of the linked list be that node
head=node;
}

// Traverse LL to see the Integers are in proper order
System.out.println("LLexample2: Single Linked List of Integers 1 to 10");
ptr=head;
while(ptr!=null)
   {
   System.out.println(ptr.getElement());
   ptr=ptr.getNext();
   }
}
}
