#include
#include
using namespace std;
int selectSort(int a[],int n)
{
for(int i=1;i<=n;i++)//进行n趟排序
{
int k=i;
for(int j=i;j<=n;j++)
{
if(a[j]>a[k])//从大到小排序
{
k=j;
}
}
int temp=a[i];
a[i]=a[k];
a[k]=temp;
}
return a[n];
}
int main()
{
int a[10010];
cout<<“please input array numbers:”;
int n;
cin>>n;
cout<<“please input array order:”;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
selectSort(a,n);
cout<<“The sort well order:”;
for(int i=1;i<=n;i++)
{
printf("%d ",a[i]);
}
return 0;
}
选择排序
最新推荐文章于 2024-03-22 17:14:14 发布