// -- Some adjustments for didactic reasons ---------- typedef unsigned long uint64_t; // ok on theseus typedef unsigned char uint8_t; int putchar ( int character ); // --------------------------------------------------- void puts(char *str) { while (*str) { putchar(*str++); } putchar('\n'); } uint64_t strlen(char *str) { char *ch = str; while (*ch) { ++ch; } return ch - str; } void quicksort(char *A, uint64_t n) { uint64_t p; uint64_t left = 0; uint64_t right = n - 1; char tmp; if (n < 2) goto quicksort_done; p = n/2; left = 0; right = n - 1; quicksort_do: quicksort_while_left: if (A[left] >= A[p]) goto quicksort_endwhile_left; left = left + 1; goto quicksort_while_left; quicksort_endwhile_left: quicksort_while_right: if (A[p] >= A[right]) goto quicksort_endwhile_right; right = right - 1; goto quicksort_while_right; quicksort_endwhile_right: if (left>right) goto quicksort_endif_left_right; tmp = A[left]; A[left] = A[right]; A[right] = tmp; if (left != p) goto quicksort_if_p_eq_right; p = right; goto quicksort_endif_p; quicksort_if_p_eq_right: if (right != p) goto quicksort_endif_p; p = left; quicksort_endif_p: left = left + 1; right = right - 1; quicksort_endif_left_right: if (left <= right) goto quicksort_do; quicksort(A, right + 1); quicksort(A+left, n - left); quicksort_done: ; } char msg[] = "hello, world!"; int main() { puts(msg); quicksort(msg, strlen(msg)); puts(msg); }