diff options
Diffstat (limited to 'test_deliverable/testcases/test_QUICKSORT.c')
-rw-r--r-- | test_deliverable/testcases/test_QUICKSORT.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test_deliverable/testcases/test_QUICKSORT.c b/test_deliverable/testcases/test_QUICKSORT.c new file mode 100644 index 0000000..adceccd --- /dev/null +++ b/test_deliverable/testcases/test_QUICKSORT.c @@ -0,0 +1,31 @@ +void quickSort(int*, int, int); +int partition(int*, int, int); + +void quickSort(int *a, int l, int r) +{ + int j; + + if( l < r ) + { + j = partition( a, l, r); + quickSort( a, l, j-1); + quickSort( a, j+1, r); + } + +} + +int partition(int *a, int l, int r) { + int pivot, i, j, t; + pivot = a[l]; + i = l; j = r+1; + + while( 1) + { + do ++i; while( a[i] <= pivot && i <= r ); + do --j; while( a[j] > pivot ); + if( i >= j ) break; + t = a[i]; a[i] = a[j]; a[j] = t; + } + t = a[l]; a[l] = a[j]; a[j] = t; + return j; +} |