用C++ 编写一个排序函数,用选择法对一批整数按从大到小的次序进行排序。

2025-03-28 13:11:29
推荐回答(1个)
回答1:

#include
using namespace std;

void xzpx(int a[], int n) // 选择排序
{
int i,j;
for(i = 0; i < n -1; i++)
for(j = i + 1; j < n; j++)
{
if(a[i] < a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
for(i = 0; i < n; i++)
cout< cout<}

int main()
{
int i;
int a[10];
for(i = 0; i < 10; i++)
cin>>a[i];
xzpx(a,10);
return 0;
}