aboutsummaryrefslogtreecommitdiffstats
path: root/test_deliverable
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-05-06 15:59:20 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-05-06 15:59:20 +0100
commit196e84b11515d10fb4023a7d5975b2cd0b2d1271 (patch)
tree74c03cdca6b14d61fcd56027cc45b41f050eb469 /test_deliverable
parent7e8ce5d95035e06a62f3d1a6f5b716863cc71829 (diff)
downloadCompiler-196e84b11515d10fb4023a7d5975b2cd0b2d1271.tar.gz
Compiler-196e84b11515d10fb4023a7d5975b2cd0b2d1271.zip
Fixed decrement
Diffstat (limited to 'test_deliverable')
-rw-r--r--test_deliverable/testcases/test_QUICKSORT.c31
-rw-r--r--test_deliverable/testcases/test_QUICKSORT_driver.c9
2 files changed, 40 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;
+}
diff --git a/test_deliverable/testcases/test_QUICKSORT_driver.c b/test_deliverable/testcases/test_QUICKSORT_driver.c
new file mode 100644
index 0000000..9ba336e
--- /dev/null
+++ b/test_deliverable/testcases/test_QUICKSORT_driver.c
@@ -0,0 +1,9 @@
+void quickSort(int*, int, int);
+
+int main()
+{
+ int a[9] = { 7, 12, 1, -2, 0, 15, 4, 11, 9};
+ quickSort( a, 0, 8);
+
+ return !( a[0]==-2 && a[1]==0 && a[2]==1 && a[3]==4 && a[4]==7 && a[5]==9 && a[6]==11 && a[7]==12 && a[8]==15 );
+}