Qt排序

void qsort(void *base,int nelem,int width,int (*fcmp)(const void *,const void *));//1
void qSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan);//2
void qSort(RandomAccessIterator begin, RandomAccessIterator end);//3

1、要求传入起始指针,总长度,单元素空间占用大小(sizeof(A[i])),判断函数。

判断函数参数类型为const void *,使用需要在函数内自行转换为对应类型,

返回值为整数型,升序排序时正表示参数1大于参数2,0表示相等,负表示小于

2、范例如下

QList<TTT *> mlist;
qSort(mlist.begin(),mlist.end(),cmp);
bool cmp(const TTT *a, const TTT *b) { return a->num()>b->num()?true:false; }

博客地址已更改,文章数量较多不便批量修改,若想访问源文请到 coologic博客 查阅,网址:www.coologic.cn

如本文记录地址为 techieliang.com/A/B/C/ 请改为 www.coologic.cn/A/B/C/ 即可查阅

 
原文地址:https://www.cnblogs.com/techiel/p/7500809.html