|
|
Scott,
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.
--Justin
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
Scott
________________________________
From: Justin Noel [mailto:justin@xxxxxxx]
Sent: Tue 10/31/2006 9:56 AM
To: qt-interest
Subject: Re: Différence of QStringLists
max wrote:
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;
Max,
How about:
QStringList res;
foreach(QString str, list1)
{
if( !list2.contains(str) )
res << str;
}
--Justin
--
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/
justin.vcf
Description: Vcard
|
|