- #include <stdio.h>
- #include <string.h>
- /**
- * 字符串排序
- *
- * @param arr 字符串指针数组
- * @param len 数组长度
- */
- void paiXu(char *arr[],int len){
- char *temp;
- for (int i=0; i<len-1; i++) {
- for (int j =0; j<len-i-1; j++) {
- if (strcmp(arr[j], arr[j+1])>0) {
- temp=arr[j];
- arr[j]=arr[j+1];
- arr[j+1]=temp;
- }
- }
- }
- }
- int main(int argc, const char * argv[]) {
- char*name[]={"CHINA","AMERICA","AUSTRALIA","FRANCE","GERMAN" };
- for (int i =0; i<5; i++) {
- printf("%s\n",name[i]);
- }
- printf("\n");
- paiXu(name, 5);
- for (int i =0; i<5; i++) {
- printf("%s\n",name[i]);
- }
- return 0;
- }
复制代码
|
|