需求:

"ff555d", "114ddd", "114dd","aaa", "aaab", "aaa" d对它们进行排序

头文件:

#include<stdlib.h>
#include<stdio.h>
#include<string.h>

函数原型:

void printArray(char **buff,int len);

void sortBuff(char **buff[],int len);

实现方法:

void printArray(char **buff, int len){

    int i;

    for (i = 0; i < len; ++i){
        printf("%s\n", buff[i]);
    }

}
 
 1 void sortBuff(char **buff,int len){
 2 
 3     char *temp;    //零时交换变量
 4 
 5     int i, j;
 6 
 7     /*选择排序法*/
 8     for (i = 0; i < len; ++i){
 9 
10         for (j = i + 1; j < len; ++j){
11 
12             if( strcmp(buff[i], buff[j]) > 0){ //应用string.h  
13                                                 //    int strcmp(    
14                 temp = buff[i];                    //        const char *string1,
15                                                 //        const char *string2 
16                 buff[i] = buff[j];                //    );
17                                                 //string1 > string2 返回值大于0 , == 为等于0, < 为小于0
18                 buff[j] = temp;                
19             
20 
21                 
22 
23             }
24 
25         }
26 
27     }
28 
29 }
View Code

相关文章:

  • 2022-12-23
  • 2021-06-26
  • 2022-02-12
  • 2021-07-12
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
猜你喜欢
  • 2021-10-15
  • 2021-09-05
  • 2022-02-28
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
相关资源
相似解决方案