• 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: Sorting a list of records
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting a list of records


  • Subject: Re: Sorting a list of records
  • From: "Mark J. Reed" <email@hidden>
  • Date: Mon, 23 Aug 2010 20:10:52 -0400

You could pick an efficient, stable algorithm from the table at
http://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms
and implement it.  Or modify an existing one - the most efficient form
of QuickSort is not stable, but if you're willing to pay a time and
space penalty you can alter the partitioning algorithm to make it
stable, as described in its own Wikipedia entry (linked from its entry
in the above table).

If your records can be represented as single lines of text with some
sort of single-character delimiter between fields, you could use 'do
shell script "sort -s" '.

On Mon, Aug 23, 2010 at 6:58 PM, Gil Dawson <email@hidden> wrote:
> Hi, Folks--
>
> I need an algorithm to sort a list of records in a "stable" way.  By "stable", I mean
>
>        When two keys are equal, output records are in the same order as the input.
>
> The AppleScript 'CustomQsort' algorithm suggested by Adam Bell, Nigel Garvey, et al in (http://macscripter.net/viewtopic.php?id=17340) works well in my application except that the underlying QuickSort algorithm is intrinsically not "stable".
>
> I looked at the "sortlist" command in Satimage.osax.  It is stable, but it sorts a list of lists, instead of a list of records.  I would need to figure a way to "coerce" a list of records to a list of lists, then back again.
>
> Anyone have another idea?
>
> --Gil _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>



--
Mark J. Reed <email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Sorting a list of records (From: Gil Dawson <email@hidden>)

  • Prev by Date: Sorting a list of records
  • Next by Date: Re: Sorting a list of records
  • Previous by thread: Sorting a list of records
  • Next by thread: Re: Sorting a list of records
  • Index(es):
    • Date
    • Thread