#include <stdio.h>
int arr[] = {13,23,5,67,43,19,34,8,21};
#define LENGTH sizeof(arr) / sizeof(int)
void print() {
int i;
for (i = 0; i < LENGTH; i++) {
printf("%d ", arr[i]);
}
printf("
");
}
void quicksort(int* arr, int l, int h) {
int i, j, tem, key;
key = arr[l];
i = l;
j = h;
while (i < j) {
while (key <= arr[j] && i < j) {
j--;
}
if (i < j) {
tem = arr[i];
arr[i] = arr[j];
arr[j] = tem;
print();
}
while (arr[i] <= key && i < j) {
i++;
}
if (i < j) {
tem = arr[i];
arr[i] = arr[j];
arr[j] = tem;
print();
}
}
if (i - 1 > l) {
quicksort(arr, 0, i - 1);
}
if (j + 1 < h) {
quicksort(arr, j + 1, h);
}
}
int main(int argc, char* args[]) {
print();
quicksort(arr, 0, LENGTH-1);
return 0;
}