• 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: 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.


  • Follow-Ups:
    • Re: how to sort a list
      • From: Emmanuel <email@hidden>
    • Re: how to sort a list
      • From: Graff <email@hidden>
References: 
 >how to sort a list (From: Andre Vink <email@hidden>)

  • Prev by Date: Re: Getting values from keychain
  • Next by Date: Re: scripting keychain access - login keychain
  • Previous by thread: Re: how to sort a list
  • Next by thread: Re: how to sort a list
  • Index(es):
    • Date
    • Thread