/* TestIntListProcedural.java Test the integer linked list class using the usual procedural style. Bruce M. Bolden May 18, 2000 Revised: December 1, 2003 http://www.cs.uidaho.edu/~bruceb/ */ import java.io.*; class TestIntListProcedural { public static void main( String[] args ) { IntList list1 = new IntList( 1, null ); System.out.print( "list1: " ); PrintIntList( list1 ); list1 = new IntList( 1 ); //System.out.println( head(list1) ); System.out.print( "list1: " ); PrintIntList( list1 ); IntList list2 = new IntList( 2, list1 ); IntList list3 = new IntList( 3, list2 ); System.out.print( "list3: " ); PrintIntList( list3 ); //list1 = new IntList( 2, list1 ); //list1 = new IntList( 3, list1 ); list1 = new IntList( 3, new IntList( 2, list1 )); System.out.print( "list1: " ); PrintIntList( list1 ); } // List manipulation procedures (functions) static int head( IntList aList ) { return aList.value; } static IntList tail( IntList aList ) { return aList.next; } static boolean empty( IntList aList ) { return( aList == null ); } static void PrintIntList( IntList aList ) { IntList tmpList = aList; System.out.print( "{ " ); while( tmpList != null ) { System.out.print( head(tmpList) ); tmpList = tail(tmpList); if( tmpList != null ) System.out.print( ", " ); } System.out.println( " }" ); } } class IntList { int value; IntList next; IntList( int x ) { value = x; next = null; } IntList( int x, IntList aList ) { value = x; next = aList; } }