// Sort a list of 500 integers // The integers must be initialized in memory with the // perl script sort.pl (otherwise this program just sorts // 500 zeros). // java cmm --wisc sort.C sort.s // wiscas sort.s // perl sort.pl >> sort.mem int list[500]; void swap(int a, int b) { int temp; temp = list[a]; list[a] = list[b]; list[b] = temp; } void quickSort(int start, int end) { int lower; int upper; lower = start + 1; upper = end; swap(start, (start + end) / 2); while (lower <= upper) { while (list[lower] < list[start]) { lower = lower + 1; } while (list[start] < list[upper]) { upper = upper - 1; } if (lower < upper) { swap(lower, upper); lower = lower + 1; upper = upper + 1; } else { lower = lower + 1; } } swap(upper, start); if (start < upper - 1) { quickSort(start, upper - 1); } if (upper + 1 < end) { quickSort(upper + 1, end); } } void main() { int length; int i; length = 500; if (length >= 2) { int max; max = 0; i = 1; //put the largest element at the end of the array while (i < length) { if (list[max] < list[i]) { max = i; } i = i + 1; } swap(length - 1, max); quickSort(0, length - 2); } }