void quickSort(int * a, int low, int high);
int findPos (int * a, int low, int high);
int main(){
int a[7] = {2, 5, 7, 8, 5, 4, 1};
int i;
quickSort(a, 0, 6);
for(i=0; i<7; i++){
printf("%d ", a[i]);
}
printf("\n");
getchar();
return 0;
}
void quickSort(int * a, int low, int high){
int pos;
if(low < high){
pos = findPos(a, low, high);
quickSort(a, low, pos-1);
quickSort(a, pos+1, high);
}
}
int findPos (int * a, int low, int high){
int val = a[low];
while(low < high){
while(low < high && a[high] >= val){
--high;
}
a[low] = a[high];
while(low < high && a[low] <= val){
++low;
}
a[high] = a[low];
}
a[low] = val;
return low;
}