Skip to content

Commit 2c07bcb

Browse files
committed
Adding slow sort
1 parent 31f3021 commit 2c07bcb

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"files.associations": {
33
"*.embeddedhtml": "html",
4-
"stdlib.h": "c"
4+
"stdlib.h": "c",
5+
"stdio.h": "c"
56
}
67
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is a collection of sorting algorithms implemented in C.
1313
- Radix Sort
1414
- Bucket Sort
1515
- Shell Sort
16+
- Stooge Sort
1617

1718
Other algorithms are not still implemented:
1819

@@ -22,7 +23,6 @@ Other algorithms are not still implemented:
2223
- Cocktail Sort
2324
- Pigeonhole Sort
2425
- Cycle Sort
25-
- Stooge Sort
2626
- Bitonic Sort
2727
- Pancake Sort
2828
- Bogo Sort

a.exe

510 Bytes
Binary file not shown.

slow_sort.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
void slow_sort(int *arr, int n) {
5+
int temp;
6+
if (n == 1) {
7+
return;
8+
}
9+
for (int i = 0; i < n / 2; i++) {
10+
if (arr[i] > arr[n - i - 1]) {
11+
temp = arr[i];
12+
arr[i] = arr[n - i - 1];
13+
arr[n - i - 1] = temp;
14+
}
15+
}
16+
slow_sort(arr, n / 2);
17+
slow_sort(arr + n / 2, n - n / 2);
18+
}
19+
20+
int main(int argc, char** argv) {
21+
int arr[] = { 5, 4, 3, 2, 1 };
22+
int n = sizeof(arr) / sizeof(arr[0]);
23+
24+
slow_sort(arr, n);
25+
26+
for (int i = 0; i < n; i++) {
27+
printf("%d ", arr[i]);
28+
}
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)