// Program to test passing of functions as parameters. // Bubble sort program var a = { 7, 8, 4, 3, 2, 9, 6, 0 }, printArray = funct( a ) var i; begin print( "{ " ); for i = 0; i < size a; i = i + 1 do if i > 0 then print( ", " ); end print( a[ i ] ); end println( " }" ); end, compare = funct( a, b ) begin if a < b then return -1; elif a > b then return 1; else return 0; end end, bubbleSort = funct( a, comp, output ) var i, j, swap = funct( a, x, y ) var temp; begin temp = a[ x ]; a[ x ] = a[ y ]; a[ y ] = temp; end; begin output( a ); for i = size a - 1; i > 0; i = i - 1 do for j = 0; j < i; j = j + 1 do if comp( a[ j ], a[ j + 1 ] ) > 0 then swap( a, j, j + 1 ); output( a ); end end end end; begin bubbleSort( a, compare, printArray ); end.