#include <QCoreApplication>
#include <QVector>
#include <QDebug>
#include <QtAlgorithms>
typedef QVector<int>CMyVector;
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.toLower() < s2.toLower();
}
bool Greater(const qint32 &a1, const qint32 &a2)
{
return a1 < a2;
}
//qt通用算法
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//string 排序
QStringList list;
list << "AlPha" << "beTA" << "gamma" << "DELTA";
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
// list: [ "AlPha", "beTA", "DELTA", "gamma" ]
for (qint32 i =0; i< list.length(); i++) {
qDebug()<<list[i];
}
//vector排序
CMyVector vector;
vector<<10<<50<<1<<100;
qDebug()<<"veoctor sort";
qSort(vector.begin(),vector.end(),Greater);
for (qint32 i =0; i< vector.length(); i++) {
qDebug()<<vector[i];
}
//查找
CMyVector::iterator iterfind = qFind(vector.begin(),vector.end(),101);
if(iterfind != vector.end()){
qDebug()<<"find 101";
}
else {
qDebug()<<"not find 101";
}
return a.exec();
}