Skip to content

Commit c467157

Browse files
committed
Added working Selectionsort
1 parent 1ebf8b7 commit c467157

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Sorting/Selectionsort.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Created by Tay on 10/10/17.
3+
//
4+
5+
void selectionSort(int table[], int size) {
6+
int min, tmp;
7+
for (int i = 0; i < size - 1; i++) {
8+
min = i;
9+
for (int j = i + 1; j < size; j++) {
10+
if (table[j] < table[min]) {
11+
min = j;
12+
}
13+
}
14+
if (min != i) {
15+
tmp = table[i];
16+
table[i] = table[min];
17+
table[min] = tmp;
18+
}
19+
for (int a = 0; a < 7; a++) {
20+
std::cout << table[a] << " ";
21+
22+
}
23+
std::cout << std::endl;
24+
}
25+
}
26+
27+
int main() {
28+
int table[] = {13, 32, 43, 14, 25};
29+
selectionSort(table, 5);
30+
return 0;
31+
}

0 commit comments

Comments
 (0)