import DataStructures.*;
import Exceptions.*;
import Supporting.*;

public class TestList
{
    // Return number of elements in theList
    static public int listSize( LinkedList theList )
    {
        int size = 0;
        LinkedListItr itr = new LinkedListItr( theList );

        for( ; itr.isInList( ); itr.advance( ) )
            size++;
        return size;
    }

    // Print contents of theList
    static public void printList( LinkedList theList )
    {
        LinkedListItr itr = new LinkedListItr( theList );

        if( theList.isEmpty( ) )
            System.out.println( "Empty list" );
        else
            for( ; itr.isInList( ); itr.advance( ) )
                System.out.println( itr.retrieve( ) );
    }

    static public void main( String [ ] args )
    {
        LinkedList theList = new LinkedList( );
        SortListItr itr = new SortListItr( theList );

        for( int i = 9; i >= 0; i-- )
        {
            try
              { itr.insert( new MyInteger( i ) ); }
            catch( Exception e )
              { }
        }

        System.out.println( "Size is " + listSize( theList ) );

        for( int i = 3; i < 6; i++ )
        {
            try
              { itr.remove( new MyInteger( i ) ); }
            catch( ItemNotFound e )
              { System.out.println( "Can't delete " + i ); }
        }

        for( int i = 0; i < 10; i++ )
        {
            if( ( i >= 3 && i < 6 ) == itr.find( new MyInteger( i ) ) )
                System.out.println( "Oops -- broken list" );
        }
        printList( theList );
    }
}
