#include <iostream>
using namespace std;
void SelectionSort(int * arr,const int size)
{
if(!arr)
return ;
for (int i =0 ;i<size ;i++)
{
int pos= i ;
for (int j= i;j<size ;j++)
{
if(arr[pos] > arr[j])
pos = j ;
}
int tmp = arr[i];
arr[i] = arr[pos];
arr[pos]= tmp ;
}
}
void output(int *a, int len)
{
for(int i = 0; i < len; ++i)
{
cout << a[i] << " ";
}
cout << endl;
}
int main()
{
int a[] = {6, 9, 1, 3, 6, 8, 9, 4};
int len = sizeof(a) / sizeof(int);
output(a, len);
SelectionSort(a,len);
output(a, len);
}
07-24
57万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-18
07-18
07-18
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交