class List( int value; List next; ); void printList( List source; ) { print( "{ " ); while ( source != null ) { print( source.value ); source = source.next; if ( source != null ) print( ", " ); } print( " }" ); } void head( int n; List source; var List dest; ) { print( "Enter head( " + n + ", " ); printList( source ); print( ", " ); printList( dest ); println( " )" ); if ( n == 0 ) { dest = null; // At this point } else { dest = new List{ source.value, null }; print( "dest = " ); printList( dest ); println( "" ); head( n - 1, source.next, dest.next ); // Inside the above invocation } print( "Exit head( " + n + ", " ); printList( source ); print( ", " ); printList( dest ); println( " )" ); } List source, a2, a4, a7, a9, dest; a9 = new List{ 9, null }; a7 = new List{ 7, a9 }; a4 = new List{ 4, a7 }; a2 = new List{ 2, a4 }; source = a2; head( 2, source, dest ); // Inside this invocation printList( source ); println( "" ); printList( dest ); println( "" );