public class LinkedList<E> {

    private static class Node<E> {
        private E value;
        private Node<E> next;

        private Node( E value, Node<E> next ) {
            this.value = value;
            this.next = next;
        }
    }

    private Node<E> head = null;

    public void addFirst( E o ) {

	if ( o == null ) {
	    throw new IllegalArgumentException( "null" );
	}

        head = new Node<E>( o, head );
    }

    public int size() {
	return size( head );
    }

    private int size( Node<E> p ) {
	if ( p == null ) {
	    return 0;
	}
	return 1 + size( p.next );
    }

    public static void main( String[] args ) {

	LinkedList<Integer> l = new LinkedList<Integer>();

	for ( int i=0; i<5; i++ ) {
	    l.addFirst( i );
	}

	System.out.println( "length = " + l.size() );
    }
}

