//
// ListTest.java
// Methods for processing list nodes, mostly written to demonstrate and
//   emphasize recursive techniques
//
// Nadeem Abdul Hamid
// CSC121 - Berry College - Spring 2005
//

public class ListTest 
{

    // list printing methods
    public static void print( ListNode l )
    {
	System.out.print( "(" );
	printAux( l );            // starts the recursive printing
	System.out.print( ")" );
    } // end method print


    // auxiliary printing method that actually prints out the list recursively
    private static void printAux( ListNode l ) 
    {
	if ( l == null ) {
	    System.out.print( "[]" ); 
	    return;
	}
	
	if ( l.getHead() instanceof ListNode ) {
	    print( (ListNode) l.getHead() );
	    System.out.print( " :: " );
	}
	else { 
	    System.out.print( l.getHead() + " :: " );
	}
	
	printAux( l.getTail() );
    } // end method printAux


    // returns the length of the list
    public static int length( ListNode l )
    {
	if ( l == null ) return 0;
	else return 1 + length( l.getTail() );
    }
    


    // main method demonstrates use of the methods above
    public static void main( String args[] ) 
    {
	ListNode l1 = new ListNode( "a", new ListNode( "b", null ) );
	print( l1 );
	System.out.println();

	ListNode l2 = new ListNode( "c", new ListNode( "d", null ) );
	print( l2 );
	System.out.println();

	// TO DO: implement the append method
	//	ListNode l3 = append( l1, l2 );
	//	print( l3 );
	//	System.out.println();
	
    } // end main method

} // end class ListTest