下面网站解释比较好

http://www.cnblogs.com/heyonggang/archive/2013/11/03/3404371.html

1. qsort(C中的函数加上stdlib.h)

功 能: 使用快速排序例程进行排序
头文件:stdlib.h
用 法: void qsort(void *base,int nelem,int width,int (*fcmp)(const void *,const void *));
参数: 1 待排序数组首地址
数组中待排序元素数量
各元素的占用空间大小
指向函数的指针,用于确定排序的顺序

 

int compare(const void *a , const void *b )
return *(int *)a - *(int *)b;  //升序排序
return *(int *)b - *(int *)a; //降序排序

2.sort(C++中函数加上algorithm)

  • 升序:sort(begin,end,less<data-type>());
  • 降序:sort(begin,end,greater<data-type>())
  • 升序:sort(begin,end,cpmpare);    compare(int a, int b)   { return a < b}
  • 降序:sort(begin,end,compare).    compare(int a, int b)   { return a > b}

 

posted on 2016-09-07 20:15  人生一世,草木一秋。  阅读(29)  评论(0编辑  收藏  举报