void selectsort(int k[],int n) /*选择排序*/
{
int i,j,max;
for(i=1;i<=n-1;i++){
max = i;
for(j=i+1;j<=n;j++) /*在后n-i+1个元素找到最小的位置*/
if(k[j] > k[max])
max = j; /*用min记录最小位置*/
if(max != i){
k[0] = k[max] ;
k[max] = k[i];
k[i] = k[0];
}
}
}
void xuanze()
{
int i,a[11] = {-111,2,5,6,3,7,8,0,9,12,1}; /*初始化,a[0]任一*/
printf("The orginal data array is\n") ;
for(i=1;i<=10;i++) /*原*/
printf("%d ",a[i]);
selectsort(a,10); /*执行*/
printf("\nThe result of selection sorting for the array is\n");
for(i=1;i<=10;i++)
printf("%d ",a[i]); /*结果*/
}
阅读(1000) | 评论(1) | 转发(0) |