當前位置:成語大全網 - 書法字典 - 字典順序的數組

字典順序的數組

# include & ltstdio.h & gt

# include & ltstring.h & gt

void main()

{

void sort(char *s[],int n);

static char *name[5]={"basic "," fortran "," cobol "," pascal "," c " };

int I;

排序(名稱,5);

Printf("新排序字符串:\ n ");

for(I = 0;我& lt5;i++)

puts(name[I]);

}

void sort(char *s[],int n){

char * t;

int i,j,k;

for(I = 0;我& ltn-1;i++){

k = I;

for(j = I+1;j & ltn;j++)

if (strcmp(s[k],s[j])& gt;0)k = j;

如果(k!=i)

t=s[i],s[i]=s[k],s[k]= t;

}

}