-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplate.cpp
67 lines (54 loc) · 1.28 KB
/
Template.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
const int MAX_SIZE = 100;
int n;
template <class T>
void selection(T A[]) {
int i, j, Min;
T temp;
for (i = 0; i < n - 1; i++) {
Min = i;
for (j = i + 1; j < n; j++) {
if (A[j] < A[Min]) {
Min = j;
}
}
temp = A[i];
A[i] = A[Min];
A[Min] = temp;
}
cout << "The sorted list is: ";
for (i = 0; i < n; i++) {
cout << " " << A[i];
}
cout << endl;
}
int main() {
int i, A[MAX_SIZE];
float B[MAX_SIZE];
cout << "**Selection Sort**"<<endl;
cout << "Handling integer elements ";
cout << "How many elements are there? "<<endl;
cin >> n;
if (n > MAX_SIZE) {
cout << "Error: Maximum size exceeded. ";
return 1;
}
cout << "Enter the integer elements: ";
for (i = 0; i < n; i++) {
cin >> A[i];
}
selection(A);
cout << "How many elements are there? ";
cin >> n;
if (n > MAX_SIZE) {
cout << "Error: Maximum size exceeded. ";
return 1;
}
cout << "Enter the float elements: ";
for (i = 0; i < n; i++) {
cin >> B[i];
}
selection(B);
return 0;
}