Hello.
I think I’d post this, it is a small sort routine for Natural Numbers that I have adapted from the Ascii Sort routine of the AppleScript Guide Book
It’s purpose was/is to be able to keep track of positions between elements in two lists, where the original position of the element was stored within the list. This then sorted the numbers which represented the positions in the list back again. -After the list was sorted say by name, in order to relate the items in the list with some other list.
I must say that I use this only for small lists, say with less than 8-10 elements.
Best Regards
McUsr
(* Almost *totally* stolen from AppleScript Guidebook: Essential Sorting Routines
revamped to integers, doesn't work for zero, but that doesn't matter in the context
of natural numbers which is what we use it for since they allways are posive.
*)
(*
TERMS OF USE.
This applies only to posting code, as long as you don't post it, you are welcome to do
whatever you want to do with it without any further permission.
Except for the following: Selling the code as is, or removing copyright statmentents and the embedded link in the code (without the http:// part) from the code.
You must also state what you eventually have done with the original source. This obviously doesn't matter if you distribure AppleScript as read only. I do not require you to embed any properties helding copyright notice for the code.
Credit for having contributed to your product would in all cases be nice!
If you use this code as part of script of yours you are of course welcome to post that code with my code in it here at macscripter.net. If you then wish to post your code elsewhere after having uploaded it to MacScripter.net please email me and ask for permission.
The ideal situation is however that you then refer to your code by a link to MacScripter.net
The sole reason for this, is that it is so much better for all of us to have a centralized codebase which are updated, than having to roam the net to find any usable snippets. Which some of us probabaly originated in the first hand.
I'm picky about this. If I find you to have published parts of my code on any other site without previous permission, I'll do what I can to have the site remove the code, ban you, and sue you under the jurisdiction of AGDER LAGMANNSRETT of Norway. Those are the terms you silently agree too by using this code.
The above paragraphs are also valid if you violate any of my terms.
If you use this or have advantage of this code in a professional setting, where professional setting means that you use this code to earn money by keeping yourself more productive. Or if you as an employee share the resulting script with other coworkers, enhancing the productivity of your company, then a modest donation to MacScripter.net would be appreciated.
*)
on num_Sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to 0
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as number
if the low_item is 0 then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end num_Sort