#include "stdio.h"
int main()
{
int i,j,n;
int a[12];
int min,mx;
scanf("%d",&n);
for(i=0;i
scanf("%d",&a[i]);
}
for(i=0;i
min=a[i];
mx=i;
for(j=i+1;j
if(a[j]>min)
{
min=a[j];
mx=j;
}
}
j=a[i];
a[i]=a[mx];
a[mx]=j;
}
for(i=0;i
printf("%d ",a[i]);
}
return 0;
}
min记录该次比较的最大值,mx为相应坐标
遍历找到mx后,与a[i]换位~
#include
#include
#include
using namespace std;
void main()
{
int n,temp,i;
vector
cout<<"输入N";
cin>>n;
cout<<"输入n个数:";
for(i=0;i
cin>>temp;
array.push_back(temp);
}
sort(array.begin(),array.end());
for(i=0;i
cout<
}