[C] 快速排序 →→→→→进入此内容的聊天室

来自 , 2021-03-04, 写在 C, 查看 127 次.
URL http://www.code666.cn/view/eb76c035
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int sort_function( const void *a, const void *b);
  6.  
  7. char list[5][4] = { "cat", "car", "cab", "cap", "can" };
  8.  
  9.  
  10. int main(void)
  11. {
  12.    int  x;
  13.  
  14.    qsort((void *)list, 5, sizeof(list[0]), sort_function);
  15.    for (x = 0; x < 5; x++)
  16.       printf("%s\n", list[x]);
  17.    return 0;
  18. }
  19.  
  20. int sort_function( const void *a, const void *b)
  21. {
  22.    return( strcmp(a,b) );
  23. }
  24.  

回复 "快速排序"

这儿你可以回复上面这条便签

captcha