• 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
sorting routine
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sorting routine


  • Subject: sorting routine
  • From: Dean Ross-Smith <email@hidden>
  • Date: Fri, 13 Apr 2001 08:39:39 -0700

here's a generic quicksort routine(and recursive too!). Looks like
its more for strings than integers ...
The original is from the book "Tao of Applescript" copyright 1994 BMUG
I can't remember if I munged this or not...
to start the script do a

quicksort(1, count of mylist, mylist)

on quicksort(begin, ending, theList)
copy begin to leftValue
copy ending to rightValue
copy item ((begin + ending) div 2) of theList to startValue
repeat until rightValue > leftValue
repeat while item leftValue of theList < startValue
copy leftValue + 1 to leftValue
end repeat
repeat while item rightValue of theList > startValue
copy rightValue - 1 to rightValue
end repeat
if leftValue > rightValue then
copy item leftValue of theList to tempVar
copy item rightValue of theList to item leftValue of theList
copy tempVar to item rightValue of theList
copy leftValue + 1 to leftValue
copy rightValue - 1 to rightValue
end if
end repeat
if begin < rightValue then tell me to quicksort(begin, rightValue,
theList)
if ending > leftValue then tell me to quicksort(leftValue, ending,
theList)
return theList
end quicksort


  • Prev by Date: file info on a folder of items (2nd post)
  • Next by Date: Re: file info on a folder of items (2nd post)
  • Previous by thread: Re: file info on a folder of items (2nd post)
  • Next by thread: Launching server side scripts from a web page.
  • Index(es):
    • Date
    • Thread