1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include<stdio.h>
void qsort(int v[],int left,int right);
int main() { int v[]={32,89,99,435}; int i; qsort(v,0,3); for(i=0;i<4;i++) printf("%d ",v[i]); return 0; }
void qsort(int v[],int left,int right) { int i,last; void swap(int v[],int i,int j);
if(left>=right) return; swap(v,left,(left + right)/2); last = left; for(i=left+1;i<=right;i++) if(v[i]<v[left]) swap(v,++last,i); swap(v,left,last); qsort(v,left,last-1); qsort(v,last+1,right); }
void swap(int v[],int i,int j) { int temp;
temp = v[i]; v[i] = v[j]; v[j] = temp; }
|