RE: [Slightly OT] Sort algorithms
RE: [Slightly OT] Sort algorithms
- Subject: RE: [Slightly OT] Sort algorithms
- From: "Bourque, Jason" <email@hidden>
- Date: Thu, 20 Sep 2001 08:22:27 -0400
Serge,
Hello, if you can separate them into two list instead of one using a repeat
loop and delimiters then.
i.e.
{"email@hidden"}
to
{{"mfs.com"},{"jbourque"}}
and then send the list to the below handler it will return three sorted
lists by first by the first list then by the 2nd and so on.
on multipleListSort(listLists)
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to "@@@"
set combinedList to {}
repeat with nth from 1 to (count of item 1 of listLists)
set itemNth to {}
repeat with nth2 from 1 to (count of listLists)
try
copy item nth of item nth2 of listLists to end of
itemNth
on error
copy "-----" to end of itemNth
end try
end repeat
copy itemNth as string to end of combinedList
end repeat
my listSort(combinedList)
set combinedList to result
set listCount to count of text items of item 1 of combinedList
set separatedLists to {}
repeat listCount times
copy {} to end of separatedLists
end repeat
repeat with nth from 1 to count of combinedList
set nthItems to (text items of item nth of combinedList)
repeat with nth2 from 1 to listCount
copy item nth2 of nthItems to end of item nth2 of
separatedLists
end repeat
end repeat
set AppleScript's text item delimiters to tids
separatedLists
end multipleListSort
--set listLists to {{"c", "b", "a", "1"}, {"d", "e", "f", "z"}, {"g", "h",
"i", "x"}}
--my multipleListSort(listLists)
The above handler also needs
on listSort(myList)
copy {{}, {}} to {indexList, sortedList}
set myListCount to count of myList
repeat myListCount times
set lowItem to ""
repeat with nth from 1 to myListCount
if nth is not in indexList then
set thisItem to item nth of myList
if the lowItem is "" then
set lowItem to thisItem
set lowItemIndex to nth
else if (thisItem as text) comes before lowItem then
set lowItem to thisItem
set lowItemIndex to nth
end if
end if
end repeat
set end of sortedList to lowItem
set end of indexList to lowItemIndex
end repeat
sortedList
end listSort
Let me know how it works out.
Jason Bourque
Senior Script Developer
Publishing Automation
MFS Investment Management
617-954-5312
>
----------
>
From: Serge Belleudy-d'Espinose
>
Sent: Thursday, September 20, 2001 5:09 AM
>
To: email@hidden
>
Subject: [Slightly OT] Sort algorithms
>
>
Hi all,
>
>
I need to sort a list of email addresses, first by domain and then by user
>
- as it's done in AutoShare. So this excludes probably 99.99% of the
>
existing sort scripts/osaxen. And I also like the challenge of coding it
>
myself, so there's no problem for me eventually reinventing the wheel,
>
except that I know nothing about the various sort algorithms and when to
>
use them.
>
>
So what I'm looking for is any link to resources on sorting, and
>
eventually samples, whether they're in applescript, C - most probably, but
>
I still can read C - or pseudo-code.
>
>
Thanks,
>
>
Serge
>
--
>
\\//\//\// Serge Belleudy-d'Espinose Institut Jacques Monod
>
// // // http://www.ijm.jussieu.fr/ Univ. Jussieu - Paris
>
//\//\//\\