日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Qt工作笔记-QSort的基本使用

發(fā)布時間:2025/3/15 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt工作笔记-QSort的基本使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

如下面這個代碼:

#include <QCoreApplication> #include <QVector> #include <ctime> #include <QDebug>int main(int argc, char *argv[]) {QCoreApplication a(argc, argv);QVector<QString> qStrVec;for(int i = 100000; i > 0; i--){qStrVec << QString::number(i);}clock_t start, finish;double totalTime;start = clock();qSort(qStrVec.begin(), qStrVec.end());finish = clock();totalTime = (double)(finish - start)/CLOCKS_PER_SEC;qDebug() << "using " + QString::number(totalTime,'f',6) + " Time";return a.exec(); }

運行截圖如下:

雖然排序了,但并不是我想要的結果,調(diào)用他的第二個重載函數(shù)

?

?


改變代碼:

#include <QCoreApplication> #include <QVector> #include <ctime> #include <QDebug>bool intThan(const QString &s1, const QString &s2) {return s1.toInt() < s2.toInt(); }int main(int argc, char *argv[]) {QCoreApplication a(argc, argv);QVector<QString> qStrVec;for(int i = 100000; i > 0; i--){qStrVec << QString::number(i);}clock_t start, finish;double totalTime;start = clock();qSort(qStrVec.begin(), qStrVec.end(), intThan);finish = clock();totalTime = (double)(finish - start)/CLOCKS_PER_SEC;qDebug() << "using " + QString::number(totalTime,'f',6) + " Time";return a.exec(); }

運行截圖如下:

變量內(nèi)容如下:

總結

以上是生活随笔為你收集整理的Qt工作笔记-QSort的基本使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。