指针数组 例题

#include
#include
int main()
{
int sort(char* name[],int n);
int print(char*name[],int n);
char *name[]={"follow me","BASIC","Great Wall","FORTRAN","Computer design"};
int n=5;
sort(name,n);
print(name,n);
    return 0;
}
int sort(char* name[],int n)
{
char* temp;
int i,j,k;
for(i=0;i {
k=i;
for(j=i+1;j if(strcmp(name[k],name[i])>0) k=j;
if(k!=i)
{temp=name[i];name[i]=name[k];name[k]=temp;}
}
}
int print(char* name[],int n)
{
int i;
for(i=0;i printf("%s\n",name[i]);
}

你可能感兴趣的:(个人)