#include
#include
int main() {
int i,j,k;
char t[10];
char s[][10] = {"BASIC","FORTRAN","C","C++","COBOL","FOX PRO"};
printf("排序前 : \n");
for(i = 0;i < 5;i++) printf("%s ",s[i]);
printf("\n\n");
for(i = 0;i < 4;i++) {
for(int j = i + 1;j < 5;j++) {
k = i;
if(strcmp(s[k],s[j]) > 0) k = j;
}
if(k != i) {
strcpy(t,s[i]);
strcpy(s[i],s[k]);
strcpy(s[k],t);
}
}
printf("排序后 : \n");
for(i = 0;i < 5;i++) printf("%s ",s[i]);
printf("\n\n");
return 0;
}
用STL里的sort算法排下序就行了