Reversing a list

BNig niggemann at uni-wh.de
Thu Apr 3 09:21:31 EDT 2008


hi,

 -- Jan Schenkels solution:
##
local sLineCount, sCurrentLine

on mouseUp
    put 0 into sCurrentLine
    put the number of lines in field 1 into sLineCount
    put the millisec into tStart
    sort field 1 by ReverseOrder()
    put the millisec - tStart
end mouseUp

function ReverseOrder
    add 1 to sCurrentLine
    return sLineCount - sCurrentLine
end ReverseOrder
##

I tried this on field with 10 lines filled with number from 1 to 10, it
works and is fast.

I then tried it with a field filled with 100000 line filled with numbers
00001 to 99999

then it does not work correctly. Since I dont even understand the syntax in
the first place I have no idea why.

on the 100000 lines once the last lines are:

00020
90001
00019
00018
00017
00016
00015
00014
00013
00012
00011
00010
90000
00009
00008
00007
00006
00005
00004
00003
00002
00001

While Mark Schonewilles solution:

on mouseUp pMouseBtnNo
    put the millisec into tStart
    put field 1 into temp
    put reverseList(temp) into temp2
    put temp2 into field 1
    put the millisec - tStart
end mouseUp

function reverseList theListArray
    split theListArray by cr
    --   put the keys of theListArray
    combine theListArray by cr and tab
    sort lines of theListArray numeric descending by item 1 of each
    split theListArray by column
    return theListArray[2]
end reverseList
--

on the same list in the field works for small and large number of lines and
repeatedly and  still is very fast (580 msec) on a MacBook Pro 2.33

I didnt try where the cutoff for correct results in Jans function is.
 I thought just to mention the problem because it might not be so obvious
for lists that are not easily checked for consistency

and thanks for these functions, I always enjoy the discussions on the list

regards

Bernd

-- 
View this message in context: http://www.nabble.com/Reversing-a-list-tp16466585p16467477.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list