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 }