C++ (Qt)#include <QCoreApplication>#include <algorithm>#include <QStringList>#include <QDebug> int main(int argc, char *argv[]){ QStringList list; list <<"8c" << "1"<<"5"<<"7/9" ; std::sort(list.begin(),list.end()); qDebug() << list; return 0;}
bool sort_func(QString s1, QString s2){return s1.toInt()<s2.toInt();}
C++ (Qt)qSort( l.begin(), l.end(), []( const QString& s1, const QString& s2 ) { return strnatcmp( s1.toLocal8Bit().constData(), s2.toLocal8Bit().constData() ) < 0;} );
C++ (Qt)bool IsLess( const QString & s1, const QString & s2 ){ int limit = qMin(s1.size(), s2.size()); for (int i = 0; i < limit; ++i) { bool digit1 = s1[i].isDigit(); bool digit2 = s2[i].isDigit(); if (digit1 && digit2) { if (s1[i] == s2[i]) continue; return s1[i] < s2[i]; } return !digit1 && digit2; } return false;}
C++ (Qt)inline bool NextDigit( const QString & s, int & index ){ while (index < s.size()) if (s[index++].isDigit()) return true; return false; } bool IsLess2( const QString & s1, const QString & s2 ){ int i1 = 0, i2 = 0; while (true) { bool digit1 = NextDigit(s1, i1); bool digit2 = NextDigit(s2, i2); if (digit1 && digit2) { QChar c1 = s1[i1 - 1]; QChar c2 = s2[i2 - 1]; if (c1 == c2) continue; return c1 < c2; } return !digit1 && digit2; } return false;}
C++ (Qt)list <<"8c" << "g93" << "10"<<"5"<<"7/9" ;
C++ (Qt)int Beg2Number( const QString & s ){ char * end; return strtol(s.toAscii().constData(), &end, 10);}
C++ (Qt)QStringList lst;lst << "8" << "23" << "101" << "5" << "7";qSort(lst.begin(), lst.end());for (int i = 0; i < lst.size(); ++i) qDebug() << lst[i];
C++ (Qt)lst.sort([](const std::string& str1, const std::string& str2)->bool { sregex regex = (s1 = +_d) >> *~_d; smatch what1, what2; if (regex_search(str1, what1, regex) && regex_search(str2, what2, regex)) return std::stoi(what1[1]) < std::stoi(what2[1]); return false; });