-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.cpp
More file actions
41 lines (33 loc) · 760 Bytes
/
SelectionSort.cpp
File metadata and controls
41 lines (33 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
template<class T>
T selection() {
T a[10];
T temp;
cout << "\nSorting for 10 elements: \n";
for (int i = 0; i < 10; i++) {
cout << "a[" << i << "] = ";
cin >> a[i];
}
cout << "\nUnsorted array: \n";
for (int i = 0; i < 10; i++)
cout << a[i] << " ";
cout << endl;
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j < 10; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
cout << "\nSorted Array: \n";
for (int i = 0; i < 10; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
int main() {
selection<int>();
}