linux 下编译怎么老是出错 简单的排序解决不了了 无奈死了
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#define MAX 10
#define SWAP(x,y) {int t;t=x;x=y;y=t}
void selort(int number[])
{
int i,j,k,m;
for(i=0;i<MAX-1;i++){
m=i;
for(j=i+1;j<MAX;j++)
if(number[j]<number[m])
m=j;
if(i!=m){
SWAP(number[i],number[m]);
}
printf("第%d次排序:",i+1);
for(k=0;k<MAX;k++)
printf("%d",number[k]);
putchar('\n');
}
}
void insort(int number[])
{
int i,j,k,tmp;
for(j=1;j<MAX;j++)
{
tmp=number[j];
i=j-1;
while(tmp<number[i]){
number[i+1]=number[i];
i--;
if(i==-1)
break;
}
number[i+1]=tmp;
printf("第%d次排序:",j);
for(k=0;k<MAX;k++)
printf("%d",number[k]);
putchar('\n');
}
}
void bubsort(int number[])
{
int i,j,k,flag=1;
for(i=0;i<MAX-1&&flag==1;i++){
flag=0;
for(j=0;j<MAX-i-1;j++){
if(number[j+1]<number[j]){
SWAP(number[j+1],number[j]);
flag=1;
}
}
printf("第%d次排序:",i+1);
for(k=0;k<MAX;k++)
printf("%d",number[k]);
putchar('\n');
}
}
int main(void)
{
int number[MAX];
int i;
srand(time(NULL));
printf("排序前:");
for(i=0;i<MAX;i++){
number[i]=rand()%100;
printf("%d\t",number[i]);
}
printf("\n请选择排序方式:\n");
printf("(1)选择排序法\n");
printf("(2)插入排序法\n");
printf("(3)冒泡排序法\n");
scanf("%d",&i);
switch(i){
case 1:
selsort(number);break;
case 2:
insort(number);break;
case 3:
bubsort(number);break;
default :
printf("选项错误(1-3)\n");
}
return 0;
}