qsort 使用 qsort 函数是ANSI C标准中提供的,其声明在stdlib.h文件中,具体内容为: void qsort(void *base, size_t nelem, size_t width, int (*fcmp)(const void *, const void *)); 其中: * base 为要排序的数组 nelem 为要排序数组的长度 width 为数组元素的大小(以字节为单位) (*fcmp)(const void * a, const void * b) 为判断大小函数的指针,这个函数需要程序员自己定义, 如果a>b,函数返回1;a<b,函数返回-1;a=b,函数返回0 例:字符串排序 #i nclude <stdio.h> #i nclude <stdlib.h> #i nclude <string.h> char list[5][4]={"cat","car","cab","cap","can" }; i
2007年7月2日星期一
qsort
订阅:
博文 (Atom)