aboutsummaryrefslogtreecommitdiff
path: root/tinycc/tests/tests2/25_quicksort.c
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-07-17 01:34:34 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-07-17 01:34:34 -0300
commit88d82c6eaee88398af1de57cddca692a1f74b087 (patch)
treedf492c2002a1820959703f4f481172cceafeb0a1 /tinycc/tests/tests2/25_quicksort.c
parent111c133b939c15c57c90cd474d55e84928c6307a (diff)
Cleanup feels good! Big work coming up this week.
Diffstat (limited to 'tinycc/tests/tests2/25_quicksort.c')
-rw-r--r--tinycc/tests/tests2/25_quicksort.c83
1 files changed, 0 insertions, 83 deletions
diff --git a/tinycc/tests/tests2/25_quicksort.c b/tinycc/tests/tests2/25_quicksort.c
deleted file mode 100644
index 5cc08bd..0000000
--- a/tinycc/tests/tests2/25_quicksort.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <stdio.h>
-
-int array[16];
-
-//Swap integer values by array indexes
-void swap(int a, int b)
-{
- int tmp = array[a];
- array[a] = array[b];
- array[b] = tmp;
-}
-
-//Partition the array into two halves and return the
-//index about which the array is partitioned
-int partition(int left, int right)
-{
- int pivotIndex = left;
- int pivotValue = array[pivotIndex];
- int index = left;
- int i;
-
- swap(pivotIndex, right);
- for(i = left; i < right; i++)
- {
- if(array[i] < pivotValue)
- {
- swap(i, index);
- index += 1;
- }
- }
- swap(right, index);
-
- return index;
-}
-
-//Quicksort the array
-void quicksort(int left, int right)
-{
- if(left >= right)
- return;
-
- int index = partition(left, right);
- quicksort(left, index - 1);
- quicksort(index + 1, right);
-}
-
-int main()
-{
- int i;
-
- array[0] = 62;
- array[1] = 83;
- array[2] = 4;
- array[3] = 89;
- array[4] = 36;
- array[5] = 21;
- array[6] = 74;
- array[7] = 37;
- array[8] = 65;
- array[9] = 33;
- array[10] = 96;
- array[11] = 38;
- array[12] = 53;
- array[13] = 16;
- array[14] = 74;
- array[15] = 55;
-
- for (i = 0; i < 16; i++)
- printf("%d ", array[i]);
-
- printf("\n");
-
- quicksort(0, 15);
-
- for (i = 0; i < 16; i++)
- printf("%d ", array[i]);
-
- printf("\n");
-
- return 0;
-}
-
-/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/