#include <stdio.h>
#define ARRAY_SIZE 32
#define SWAP(a,b) ((void)(temp = (a),(a) = (b),(b) = temp))
void quicksort(int array[],size_t begin,size_t end)
{
if(begin+1 < end){
int temp;
size_t pivot = (begin+end)>>1,first2last = begin,last2first = end;
while(first2last < last2first){
while(array[first2last] < array[pivot]){
first2last++;
}
while(array[pivot] <= array[last2first]){
last2first--;
}
if(first2last < last2first){
if(pivot == first2last){
pivot = last2first;
}
SWAP(array[first2last],array[last2first]);
}
}
SWAP(array[pivot],array[first2last]);
quicksort(array,begin,last2first);
quicksort(array,first2last+1,end);
}
}
#undef SWAP
int main(void)
{
int array[ARRAY_SIZE];
unsigned long random_seed = time(NULL);
size_t counter = 0;
while(counter != ARRAY_SIZE){
array[counter] = rand()%64;
printf("%02d ",array[counter]);
counter++;
}
printf("\n");
quicksort(array,0,ARRAY_SIZE-1);
counter = 0;
while(counter != ARRAY_SIZE){
printf("%02d ",array[counter]);
counter++;
}
printf("\n");
return 0;
}