You could just brute force search the lists using QList::contains().
If the lists are sorted then you could do something like:
QList<int>::const_iterator a = listA.constBegin();
QList<int>::const_iterator b = listB.constBegin();
while (a != listA.constEnd() && b != listB.constEnd()) {
if (*a > *b)
++b;
else {
if (*a == *b)
qDebug() << *a;
++a;
}
}
QList<int>::const_iterator a = listA.constBegin();
QList<int>::const_iterator b = listB.constBegin();
while (a != listA.constEnd() && b != listB.constEnd()) {
if (*a > *b)
++b;
else {
if (*a == *b)
qDebug() << *a;
++a;
}
}
To copy to clipboard, switch view to plain text mode
If the lists contain no repeats then you could merge the lists, sort the compound list, and look for duplicates.
You could use a QHash<int, int> or QMap<int, int> for list B (value is just 1 or the number of instances of the key) to speed up lookup.
You could use an SQL database and query.
Lots of things affect the possibilities. Do you know anything about the values? Are they in order and does order matter? Are there duplicate values? What level of duplication? What form is the data in before you put it in the lists? Are you interested only in existence or number of instances?
Bookmarks