/**简单选择**/
#define N 10
#include<iostream>
using namespace std;
void SelectSort(int a[], int len)
{
for (int i = 0; i != len-1; i++)
{
int min = i;
for (int j = i+1; j != len; j++)
{
if (a[min] > a[j])min = j;
}
if (i != min)
{
int temp = a[i];
a[i] = a[min];
a[min] = temp;
}
cout << "第" <<i+1 << "趟:";
for (size_t i = 0; i != len; i++)
cout << *(a + i) << " ";
cout << endl;
}
}
int main()
{
int a[N] = { 0 };
for (size_t i = 0; i != N; i++)
cin >> a[i];
SelectSort(a, N);
cout << "排好后结果为:" << endl;
for (size_t i = 0; i != N; i++)
cout << a[i] << " ";
return 0;
}
12-25
12-22
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交