1. 如果不缺内存,如何使用一个具有库的语言来实现一种排序算法表示和排序集合?

  1)可以使用C语言中的快速排序qsort(参考自cplusplus),具体代码如下:

 1 /* qsort example */
 2 #include <stdio.h>      /* printf */
 3 #include <stdlib.h>     /* qsort */
 4 
 5 int values[] = { 40, 10, 100, 90, 20, 25 };
 6 
 7 int compare(const void * a, const void * b)
 8 {
 9     return (*(int*)a - *(int*)b);
10 }
11 
12 int main()
13 {
14     int n;
15     qsort(values, 6, sizeof(int), compare);
16     for (n = 0; n < 6; n++)
17         printf("%d ", values[n]);
18     return 0;
19 }
qsort

相关文章:

  • 2021-10-23
  • 2022-01-22
  • 2021-10-17
  • 2022-01-15
猜你喜欢
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-10-07
相关资源
相似解决方案