QT中使用高速排序

今天想到了用QT做一个高速排序。所以研究了一下。


由于用习惯了,C++的std::sort。就算是C的时候也用得是stdlib.h中的qsort。

手写板
手写板的快排事实上不难,仅仅是自从用C++打ACM之后就非常少裸敲了。

当中C语言 stdlib
功 能: 使用高速排序例程进行排序
用 法: void qsort(void base,int nelem,int width,int (*fcmp)(const void ,const void *));
參数:
1 待排序数组首地址
2 数组中待排序元素数量
3 各元素的占用空间大小
4 指向函数的指针,用于确定排序的顺序
这个库函数在QT中是支持的,但是我如今是用不太来这个东西。并且这个的函数对STL的排序不太支持。

接着用标准库中< algorithm >的sort排序。这是C++中一个专门针对泛型数据排序的中能够吧 。但是写在qt中却无法识别sort、std::sort。

事实上能够理解String转化为QString,所以我们推測 是qSort。


使用方法和sort差点儿相同。

Header: < algorithm> Namespace: std

bool CapitySort(const SVideoChip msVideoFirst,const SVideoChip msVideoSecond)  
{  
    return (msVideoFirst.mi64VideoCapacity < msVideoSecond.mi64VideoCapacity);  
}  

void * VideoSort(QList<SVideoChip>* msVideoChipList)  
{  
  qSort(msVideoChipList->begin(),msVideoChipList->end(),CapitySort);  
   // std::sort(msVideoChipList->begin(),msVideoChipList->end(),CapitySort);  
}  
原文地址:https://www.cnblogs.com/gccbuaa/p/7111480.html