qsort函数介绍:
qsort函数stdlib.h文件中,函数原型为
void qsort(void *base,size_t nelem,size_t width,int (*Comp)(const void *,const void *));
*base 为要排序的数组
nelem 为要排序的数组的长度
width 为数组元素的大小(一字节为单位)
默认是从小到大排序的!
(* Comp)(const void *p1,const void *p2) 为判断大小函数的指针,这个函数需要自己定义,如果p1>p2,函数返回-1;a
代码示例:
#include#include#includestruct Stu{
char name[100]; //名字 char xue[100]; //学号 int c; //成绩 }stu[10010];int comp(const void* a,const void* b){
struct Stu *aa = (struct Stu *)a; struct Stu *bb