Skip to content

Commit b33d4fa

Browse files
committed
Added working Insertionsort
1 parent c467157 commit b33d4fa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Sorting/Insertionsort.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Created by Tay on 10/11/17.
3+
//
4+
5+
void insertionSort(int table[], int size) {
6+
int key, j;
7+
for (int i = 1; i < size; i++) {
8+
key = table[i];
9+
j = i - 1;
10+
while (j >= 0 && table[j] > key) {
11+
table[j + 1] = table[j];
12+
j--;
13+
}
14+
table[j + 1] = key;
15+
}
16+
}
17+
18+
int main() {
19+
int table[] = {13, 32, 43, 14, 25};
20+
insertionSort(table, 5);
21+
return 0;
22+
}
23+

0 commit comments

Comments
 (0)