#define MAX 6
#include <stdio.h>
int main(int argc, const char * argv[])
{
int a[6]={9,7,5,8,4,2};
int temp = 0,p=0;
for (int i=0; i<MAX-1; i++)
{
p=i;
for (int j= i+1; j<MAX; j++)
{
if (a[j]>a[p])
p =j;
if(p!=i)
{
temp =a[p];
a[p]=a[i];
a[i]=temp;
}
}
}
for (int x= 0; x<6; x++) {
printf("a[%d] = %d\n",x,a[x]);
}
return 0;
}
选择排序法 弄不懂
最新推荐文章于 2023-03-05 11:11:00 发布