#include
#include
void sort(char *name[],int n);
void print(char *name[],int n);
int main()
{
char *name[]={"C programming","BASIC","Java","FORTRAN","Computer"};
int n=5;
sort(name,n);
print(name,n);
return 0;
}
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(strcmp(name[k],name[i])<0)
k=j;
if(k!=i)
{
temp=name[i];
name[i]=name[k];
name[k]=temp;
}
}
}
void print(char *name[],int n)
{
int i;
for(i=0;i<n;i++)
puts(name[i]);
}
/*
1.程序運行結果:
C programming
BASIC
Java
FORTRAN
Computer
*/
====求教該程序是比較字符串大小嗎?為何結果是那樣呢?求程序詳細解釋
//這裡是j
if(strcmp(name[j],name[i]) < 0)
k=j;