Re: how to sort a list
Re: how to sort a list
- Subject: Re: how to sort a list
- From: Graff <email@hidden>
- Date: Thu, 13 May 2004 21:09:28 -0400
You could use the shell or you could implement your own sort routine.
If the list you are sorting is pretty short then a bubble sort is the
best thing:
------
on BubbleSort(theList)
if class of theList is list then
set theSize to length of theList
repeat with i from 1 to theSize
repeat with j from 2 to (theSize - i + 1)
if ((item (j - 1) of theList) > (item j of theList)) then
set temp to (item (j - 1) of theList)
set (item (j - 1) of theList) to (item j of theList)
set (item j of theList) to temp
end if
end repeat
end repeat
return theList
else
return false
end if
end bubblesort
BubbleSort({"c", "b", "e", "a", "d"})
--> {"a", "b", "c", "d", "e"}
BubbleSort({name:"bill", age:12})
--> false
------
If you have really large lists (on the order of thousands of items)
then you might want to do a shell or quick sort. I have those
implemented in AppleScript so let me know if you need them. Honestly
though, if you are sorting more than a few thousand items with
AppleScript then you might want to look at going to another language
such as C or Java or the like.
- Ken
On May 13, 2004, at 4:00 PM, Andre Vink wrote:
Hi list,
how to sort a list?
{ "c", "b", "e", "a", "d" }
to
{ "a", "b", "c", "d", "e" }
andre
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.