public class LinkedList<E> implements List<E> {

    private Node<E> head = null;
    private int size = 0;

    private static class Node<T> {

	private T value;
	private Node<T> next;

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

    private class LinkedListIterator implements Iterator<E> {

	private Node<E> current;
        
	public boolean hasNext() {
	    return ( ( (current == null) && (head != null) ) || 
		     ( (current != null) && (current.next != null) ) );
	}

	public E next() {
	    if ( current == null ) {
		current = head;
	    } else {
		current = current.next;
	    }
	    return current.value;
	}
    }

    public Iterator<E> iterator() {
        return new LinkedListIterator();
    }

    public int size() {
	return size;
    }

    public E get( int pos ) {

	if ( pos < 0 || pos >= size ) {
	    throw new IndexOutOfBoundsException( Integer.toString(pos) );
	}

	E result;
	Node<E> p = head;

	for (int i=0; i<pos; i++) {
	    p = p.next;
	}

	return p.value;
    }

    public void addFirst(E e) {
    
        if ( e == null ) {
	    throw new IllegalArgumentException( "null" );
	}

	head = new Node<E>(e, head);
	size++;
    }

    public void test() {
        Node<E> p = head;
        while (p != null) {
	    E o = p.value;
            p = p.next;
        }
    }

}

