#include <stdio.h>
#pragma warning(disable:4996)
void quicksort(int*, int, int);
void printarr(int*, int, int);
int main(void) {
int arr1[10] = { 4, 2, 1, 5, 3, 6, 2, 5, 3, 0 };
int arr2[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int arr3[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
int arr4[10] = { 0, 1, 1, 1, 0, 3, 2, 2, 1, 0 };
printarr(arr1, 0, 9);
quicksort(arr1, 0, 9);
printarr(arr1, 0, 9);
printf("\n====================\n");
printarr(arr2, 0, 9);
quicksort(arr2, 0, 9);
printarr(arr2, 0, 9);
printf("\n====================\n");
printarr(arr3, 0, 9);
quicksort(arr3, 0, 9);
printarr(arr3, 0, 9);
printf("\n====================\n");
printarr(arr4, 0, 9);
quicksort(arr4, 0, 9);
printarr(arr4, 0, 9);
printf("\n====================\n");
return 0;
}
void quicksort(int* arr, int s, int e) {
if (e - s < 1) return;
int k = s;
int t = 0;
for (int i = s + 1; i <= e; i++) {
if (arr[s] > arr[i]) {
t = arr[k + 1];
arr[k + 1] = arr[i];
arr[i] = t;
k++;
}
}
t = arr[k];
arr[k] = arr[s];
arr[s] = t;
quicksort(arr, s, k - 1);
quicksort(arr, k + 1, e);
}
void printarr(int* arr, int s, int e) {
int i;
printf("Printing array.... { ");
for (i = s; i < e; i++) {
printf("%d, ", arr[i]);
}
printf("%d }\n", arr[e]);
}