/**简单选择**/
#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;
}
简单选择排序
最新推荐文章于 2022-12-29 09:58:25 发布