-- A V Peterson 05-2001 -- AVP minor mods 05-2002 -- COMP1100 Lab Week 10 class TEST_SORT -- Test bed for checking understanding of various sort routines creation make feature sorter : MY_SORTER -- contains a number of sort routines make is local n_tests : INTEGER -- number of tests arr : ARRAY[INTEGER] arr01 : ARRAY[INTEGER] arr02 : ARRAY[INTEGER] arr03 : ARRAY[INTEGER] arr04 : ARRAY[INTEGER] arr05 : ARRAY[INTEGER] i : INTEGER do !!sorter -- create some explicit arrays for testing; -- you can change these or add additional arrays n_tests := 5 arr01 := << 6, 1, 15, 3, 5, 9 >> arr02 := << 2, 4, 6, 8, 10 >> arr03 := << 100, 80, 60, 40, 20 >> arr04 := << 2, 1 >> arr05 := << 3 >> from i := 1 until i > n_tests loop inspect i when 1 then arr := arr01 when 2 then arr := arr02 when 3 then arr := arr03 when 4 then arr := arr04 when 5 then arr := arr05 end -- inspect -- heading io.put_string("Test "); io.put_integer(i); io.put_new_line io.put_string(" Initial array : "); io.put_new_line print_arr(arr) -- uncomment one sort routine call sorter.selection_sort(arr) -- sorter.insertion_sort(arr) -- sorter.bubble_sort(arr) -- sorter.gap_sort(arr) -- sorter.quick_sort(arr) -- sorter.heap_sort(arr) io.put_string(" Sorted array : "); io.put_new_line print_arr(arr) io.put_new_line i := i + 1 end -- loop end -- make print_arr(data : ARRAY[INTEGER]) is local i : INTEGER do from i := data.lower until i > data.upper loop io.put_integer_format(data.item(i), 6) i := i + 1 end -- loop io.put_new_line end -- print_arr end -- class TEST_SORT