Skip to content

Commit ab9514b

Browse files
committed
insertion_sort
1 parent d868ad0 commit ab9514b

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

Diff for: README.md

+36
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
# Sorting Algorithms (Sort)
22

3+
This is a collection of sorting algorithms implemented in C.
4+
5+
## Algorithms
6+
7+
- Bubble Sort
8+
- Insertion Sort
9+
- Selection Sort
10+
- Merge Sort
11+
- Quick Sort
12+
13+
Other algorithms are not still implemented:
14+
15+
- Heap Sort
16+
- Counting Sort
17+
- Radix Sort
18+
- Bucket Sort
19+
- Shell Sort
20+
- Comb Sort
21+
- Gnome Sort
22+
- Cocktail Sort
23+
- Pigeonhole Sort
24+
- Cycle Sort
25+
- Stooge Sort
26+
- Bitonic Sort
27+
- Pancake Sort
28+
- Bogo Sort
29+
- Bogosort
30+
- Slow Sort
31+
- Smooth Sort
32+
- Strand Sort
33+
- Tree Sort
34+
- Cube Sort
35+
- Odd-Even Sort
36+
- Bitonic Sort
37+
- Brick Sort
38+

Diff for: a.exe

-510 Bytes
Binary file not shown.

Diff for: insertion_sort.c

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

0 commit comments

Comments
 (0)