>>on revert theList
>> nb = theList.count()
>>
>> repeat with i = 1 to nb/2
>> tmp = theList[i]
>> theList[i] = theList[nb+1-i]
>> theList[nb+1-i] = tmp
>> end repeat
>>end
>>
>>This one using just one list: memory economy and is faster than colin's (for
>>a list of 10 elements, Colin's algorithm is doing 20 operations, mine's
>>doing only 15).
>
>
>I'm not so sure about your 20/15 comparison. In mine I was doing an
>append of a get, in effect, which for a six element list is 12
>operations. In yours you're doing a get, then a set of another get,
>followed by another set. You do that for half the list amount, but
>it still totals 12 operations.
I compared the solutions using a list of 10,000 elements, outputting
the time in milliseconds:
-- "Holgate: 816"
-- "Brigaut: 35"
My guess is that the prepending and pushing of the elements of a list
takes a lot of time...
If you really want to optimize Mr. Brigaut's handler you should of
course precount the nb/2 and the nb + 1 instead of doing it
repeatedly inside the loop, I earned about 10 % speed by doing that,
he he.
Test code:
----
on mouseDown me
theList = []
theList[10000] = "smurf"
oldMs = the milliseconds
nb = theList.count()
maxCount = nb/ 2
nbPlus1 = nb + 1
repeat with i = 1 to maxCount
tmp = theList[i]
theList[i] = theList[nbPlus1 - i]
theList[nbPlus1 - i] = tmp
end repeat
put "Brigaut: " & the milliseconds - oldMs
end
----
-A.
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]