qt-interest@trolltech.com
[Top] [All Lists]

RE: Différence of QStringLists

Subject: RE: Différence of QStringLists
From: "Scott Aron Bloom"
Date: Tue, 31 Oct 2006 10:51:06 -0800
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/

<Prev in Thread] Current Thread [Next in Thread>