#include <QtCore>
struct Elem {
Elem(int p, int v) { pos = p; val = v; }
int pos;
int val;
};
bool myLessThan(const Elem& e1, const Elem &e2){
return (e1.val < e2.val);
}
int main(int argc, char **argv) {
QList<int> random;
QList<Elem> order;
QList<int> other;
for(int i=0;i<10;++i){
random.push_back(qrand()%100);
order.push_back(Elem(i,random.at(i)));
other.push_back(qrand()%100);
}
qStableSort(order.begin(), order.end(), myLessThan);
QList<int> sorted;
for(int i=0;i<other.size();++i){
sorted.push_back(other.at(order.at(i).pos));
}
qDebug() << "R:" << random;
qDebug() << "O:" << other;
qDebug() << "S:" << sorted;
}
#include <QtCore>
struct Elem {
Elem(int p, int v) { pos = p; val = v; }
int pos;
int val;
};
bool myLessThan(const Elem& e1, const Elem &e2){
return (e1.val < e2.val);
}
int main(int argc, char **argv) {
QList<int> random;
QList<Elem> order;
QList<int> other;
for(int i=0;i<10;++i){
random.push_back(qrand()%100);
order.push_back(Elem(i,random.at(i)));
other.push_back(qrand()%100);
}
qStableSort(order.begin(), order.end(), myLessThan);
QList<int> sorted;
for(int i=0;i<other.size();++i){
sorted.push_back(other.at(order.at(i).pos));
}
qDebug() << "R:" << random;
qDebug() << "O:" << other;
qDebug() << "S:" << sorted;
}
To copy to clipboard, switch view to plain text mode
R: (13, 8, 77, 38, 91, 66, 69, 91, 61, 30)
O: (7, 91, 99, 63, 92, 7, 8, 39, 43, 61)
S: (91, 7, 61, 63, 43, 7, 8, 99, 92, 39)
R: (13, 8, 77, 38, 91, 66, 69, 91, 61, 30)
O: (7, 91, 99, 63, 92, 7, 8, 39, 43, 61)
S: (91, 7, 61, 63, 43, 7, 8, 99, 92, 39)
To copy to clipboard, switch view to plain text mode
Bookmarks