今天想到了用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);
}