[求助]输出的元素少了一个
原程序:
main()
{void sort(char *name[],int n);
void print(char *name[],int n);
char *name[]={"Fllow me","BASIC","Great Wall","FORTRAN","computer design"};
int n=5;
sort(name,5);
print(name,5);
getch();
}
void sort(char *name[],int n)
{char *temp;
int i,j,k;
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(*name[k]>*name[j]&& *name[k]!='\0'&& *name[j]!='\0')k=j;
if(k!=i)
{temp=name[i];name[i]=name[j];name[j]=temp;}
}
}
void print(char *name[],int n)
{int i;
for(i=0;i<n;i++)
printf("%s\n",name[i]);
}
运行结果:
urbo-C - Copyright (c) 1988 Borland Intl.
BASIC
Fllow me
FORTRAN
computer design
不明白
[此贴子已经被作者于2006-3-17 13:54:40编辑过]