• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to sort a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to sort a list


  • Subject: Re: how to sort a list
  • From: Heinrich Bjerregaard <email@hidden>
  • Date: Fri, 14 May 2004 09:31:45 +0200

On 14/5-2004, at 1:44, eric m katerman <email@hidden> wrote:

> Hi list,
>
> how to sort a list?
>
> { "c", "b", "e", "a", "d" }
> to
> { "a", "b", "c", "d", "e" }
>
> andre

You could just make a QuickSort like this:

on QSort(L) -- L is a list of items; result is the list sorted in
ascending order
set countL to count of L
if (countL < 2) then return L

set L1 to {}
set L2 to {}
set L3 to {}
set Vidx to (countL + 1) / 2 as integer
set Vval to item Vidx of L

repeat with idx from 1 to countL
set IVal to (item idx of L)
if (IVal < Vval) then
copy IVal to end of L1
else if (IVal = Vval) then
copy IVal to end of L2
else
copy IVal to end of L3
end if
end repeat
return QSort(L1) & L2 & QSort(L3)
end QSort

QSort({"c", "b", "e", "a", "d"}) & QSort({7, 1, 5, 3, 2, 8, 9, 10, 6})

-- result: {"a", "b", "c", "d", "e", 1, 2, 3, 5, 6, 7, 8, 9, 10}

Regards Heinrich
_______________________________________________
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.


  • Prev by Date: Re: keychain scripting
  • Next by Date: Re: Aliases in AppleScripts
  • Previous by thread: Re: how to sort a list
  • Next by thread: Applescript bundle droplet problems
  • Index(es):
    • Date
    • Thread