• 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 Solution Revisited was Sorting A List - Need Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting a List Solution Revisited was Sorting A List - Need Help


  • Subject: Re: Sorting a List Solution Revisited was Sorting A List - Need Help
  • From: Rick Bargerhuff alias cougar <email@hidden>
  • Date: Fri, 1 Aug 2003 02:03:13 -0400

Hello all & Nigel,

My modification of it sorts a list of *lists*, sorting on the
same-numbered item in each sublist. It thus needs a fourth parameter
which is the number of this item.

(* QuickSort handler adapted from Arthur Knapp *)

on QuickSortOnItem(theList, leftLimit, rightLimit, sublistItem)
-- Quicksorts a list of lists, sorting on item sublistItem of each
list

local leftIndex, rightIndex, comparisonValue

-- Much thanks to both Serge Belleudy-d'Espinose and Victor Yee
-- for the script-referencing techniques that they helped to
-- refine.
--
script theScriptObject
property listProperty : theList
end script

set leftIndex to leftLimit
set rightIndex to rightLimit
set comparisonValue to theScriptObject's listProperty's item
((leftLimit + rightLimit) div 2)'s item sublistItem

repeat while (rightIndex > leftIndex)
repeat while (theScriptObject's listProperty's item leftIndex's
item sublistItem < comparisonValue)
set leftIndex to leftIndex + 1
end repeat

repeat while (theScriptObject's listProperty's item rightIndex's
item sublistItem > comparisonValue)
set rightIndex to rightIndex - 1
end repeat

if rightIndex  leftIndex then
tell theScriptObject's listProperty's item leftIndex
set theScriptObject's listProperty's item leftIndex to
theScriptObject's listProperty's item rightIndex
set theScriptObject's listProperty's item rightIndex to it
end tell
set leftIndex to leftIndex + 1
set rightIndex to rightIndex - 1
end if
end repeat

if (leftLimit < rightIndex) then QuickSortOnItem(theScriptObject's
listProperty, leftLimit, rightIndex, sublistItem)
if (rightLimit > leftIndex) then QuickSortOnItem(theScriptObject's
listProperty, leftIndex, rightLimit, sublistItem)
end QuickSortOnItem


set ListOfLists to {{1, 2, 3, 4, 5}, {23, 75, 1, 0, 7}, {-3, 56, -8, 5,
5}}

-- Sort *all three* sublists on their *third items* - ie. 3, 1, and -8
QuickSortOnItem(ListOfLists, 1, count ListOfLists, 3)

ListOfLists
-- {{-3, 56, -8, 5, 5}, {23, 75, 1, 0, 7}, {1, 2, 3, 4, 5}}

How in the world does the original list get set to the sorted list?
ListOfLists variable is not a property nor a global property? And
your not calling set ListOfLists to QuickSortOnItem(. . .)

How?

Also, I don't understand you modification to Author Knapps Code.


set ListOfLists to {{1, 2, 3, 4, 5}, {23, 75, 1, 0, 7}, {-3, 56, -8, 5, 5}
-- Sort *all three* sublists on their *third items* - ie. 3, 1, and -8

Result:
-- {{-3, 56, -8, 5, 5}, {23, 75, 1, 0, 7}, {1, 2, 3, 4, 5}}

This does not make sense to me. I don't think I fully understand what the phrase
"sort on" means.

Can you please explain your modification and also let me know if we can
speed up my implementation using such tweaks as the "Serge" list referencing
technique for speed. which is at..

http://mywpages.comcast.net/cougar718/files/Human_Sort_via_QuickSort.sit

Thanks Nigel,

Rick Bargerhuff alias cougar
Programmer / Developer / Computer Specialist
Personal Email: email@hidden
Personal Website : http://mywebpages.comcast.net/cougar718
_______________________________________________
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.

References: 
 >Re: Sorting a List Solution Revisited was Sorting A List - Need Help (From: Nigel Garvey <email@hidden>)

  • Prev by Date: Re: Sorting a List Solution Revisited was Sorting A List - Need Help
  • Next by Date: RE: Numbers in a variable
  • Previous by thread: Re: Sorting a List Solution Revisited was Sorting A List - Need Help
  • Next by thread: Re: Sorting A List Solution Revisited was Sorting A List - Need Help
  • Index(es):
    • Date
    • Thread