diff options
Diffstat (limited to 'test/c/qsort.c')
-rw-r--r-- | test/c/qsort.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/c/qsort.c b/test/c/qsort.c new file mode 100644 index 00000000..9f8e5b18 --- /dev/null +++ b/test/c/qsort.c @@ -0,0 +1,16 @@ +void quicksort(int lo, int hi, int base[]) +{ + int i,j; + int pivot,temp; + + if (lo<hi) { + for (i=lo,j=hi,pivot=base[hi];i<j;) { + while (i<hi && base[i]<=pivot) i++; + while (j>lo && base[j]>=pivot) j--; + if (i<j) { temp=base[i]; base[i]=base[j]; base[j]=temp; } + } + temp=base[i]; base[i]=base[hi]; base[hi]=temp; + quicksort(lo,i-1,base); quicksort(i+1,hi,base); + } +} + |