如下面这个代码:
#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();
}
运行截图如下:
虽然排序了,但并不是我想要的结果,调用他的第二个重载函数
改变代码:
#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();
}
运行截图如下:
变量内容如下: