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
| #include <iostream>
using namespace std;
void printArr(int n,int a[]){
for (int i=0; i<n; i++) {
cout<<a[i]<<" ";
}
cout<<endl;
}
void simpleSelectionSort(int n,int a[]){
for (int i=0; i<n; i++) {
int k = i;
int tmp;
for (int j = i+1; j<n; j++) {
if (a[j]<a[k]) {
k = j;
}
}
tmp = a[i];
a[i] = a[k];
a[k] = tmp;
printArr(n, a);
}
}
int main(int argc, const char * argv[]) {
int a[] = {2,4,5,1,9,8,6,4,5};
simpleSelectionSort(9, a);
return 0;
}
|