Re: Alphabetizing a List
Re: Alphabetizing a List
- Subject: Re: Alphabetizing a List
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 28 May 2001 09:15:15 -0400
- Organization: [very little]
>
Date: Thu, 24 May 2001 23:41:52 +0200
>
To: Eric Schult <email@hidden>, <email@hidden>
>
From: Emmanuel <email@hidden>
>
Subject: Re: Alphabetizing a List
>
>
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
I tried this script and got the original list as the result. The sort
handler never got past "if length of l > 1 then return l" because the
list had more than one item.