Re: Alphabetizing a List
Re: Alphabetizing a List
- Subject: Re: Alphabetizing a List
- From: Emmanuel <email@hidden>
- Date: Thu, 24 May 2001 23:41:52 +0200
At 14:54 +0200 21/05/01, Eric Schult wrote:
>
>
Is there are painless way to alphabetize a list?
In case you did not get a reply:
-------------------------------
on sort(l)
if length of l > 1 then return l
set x to item 1 of l
set ll to rest of l
set l1 to {}
set l2 to {}
repeat with i in ll
if x < i then
set l2 to l2 & i
else
set l1 to l1 & i
end if
end repeat
if length of l1 > 1 then set l1 to sort(l1)
if length of l2 > 1 then set l2 to sort(l2)
return l1 & x & l2
end sort
-------------------------------
set theList to {"painless", "way", "to", "alphabetize", "a", "list"}
sort(theList)
-- {"a", "alphabetize", "list", "painless", "to", "way"}
HTH
Emmanuel