public class LinkedList2<E>
{
    private ListNode2<E> head;
	
    public LinkedList2( )
    {
        head = null;
    }
	
    public void showList( )
    {
        ListNode2<E> position = head;
        while (position != null)
        {
            System.out.println(position.getData( ));
            position = position.getLink( );
        }
    }
	
    public int length( )
    {
        int count = 0;
        ListNode2<E> position = head;
        while (position != null)
        {
            count++;
            position = position.getLink( );
        }
        return count;
    }
	
    public void addANodeToStart(E addData)
    {
        head = new ListNode2<E>(addData, head);
    }
	
    public void deleteHeadNode( )
    {
        if (head != null)
        {
            head = head.getLink( );
        }
        else
        {
            System.out.println("Deleting from an empty list.");
            System.exit(0);
        }
    }
	
    public boolean onList(E target)
    {
        return find(target) != null;
    }
	
    private ListNode2<E> find(E target)
    {
        boolean found = false;
        ListNode2<E> position = head;
        while (position != null)
        {
            E dataAtPosition = position.getData();
            if (dataAtPosition.equals(target))
                found = true;
            else
                position = position.getLink();
        }
        return position;
    }
}