Good point, no more posting before coffee. There is also the not so
minor issue of missing unique items if list2 is longer, oops. Another
really nice thing about your suggestion is Qt's STL iterators are
compatible with STL algorithms. Using Qt's containers one can have their
cake and eat it too.
Scott Aron Bloom wrote:
Just hope the lists arent that long... thats a O(N^2) algorithm
If the lists are sorted, you may want to consider just using the STL algorithm, if they are unsorted, you could presort, or convert 1 to a set, and then iterate and use the contains on the set. Then its down to a NlogN algorithm
From: Justin Noel [mailto:justin@xxxxxxx]
Sent: Tue 10/31/2006 9:56 AM
Subject: Re: Différence of QStringLists
Is there a simple way to make the difference of two QStringLists ?
QStringList list1 = a, b, c, d;
QStringList list2 = b, c;
QStringList res = list1 - list2;
res = a, d;
foreach(QString str, list1)
if( !list2.contains(str) )
res << str;
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/