Sort numbers lexicographically: Difference between revisions

m
→‎{{header|AppleScript}}: New sort handler URL and tidy-up in second script.
m (→‎{{header|AppleScript}}: New sort handler URL and tidy-up in second script.)
Line 171:
In the unlikely event of it ever being necessary to sort a ''given'' list of integers in this fashion, one possibility is to create another list containing text versions of the integers and to sort this while rearranging the integer versions in parallel.
 
<syntaxhighlight lang="applescript">use sorterAppleScript : scriptversion "Custom Iterative Ternary Merge Sort2.3.1" -- <https://macscripterMac OS X 10.net/viewtopic9 (Mavericks) or later.php?pid=194430#p194430>
use sorter : script ¬
"Custom Iterative Ternary Merge Sort" -- <www.macscripter.net/t/timsort-and-nigsort/71383/3>
 
on join(lst, delim)
on sortLexicographically(integerList) -- Sorts integerList in place.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeeddelim
set textListtxt to paragraphs of (integerListlst as text)
set AppleScript's text item delimiters to astid
return txt
end join
 
on sortLexicographically(integerList) -- Sorts integerList in place.
set textList to paragraphs of join(integerList, linefeed)
-- Sort textList, echoing the moves in integerList.
considering hyphens but ignoring numeric strings
tell sorter to sort(textList, 1, -1, {slave:{integerList}})
Line 185 ⟶ 192:
 
-- Test code:
local someIntegers
set someIntegers to {1, 2, -6, 3, 4, 5, -10, 6, 7, 8, 9, 10, 11, 12, 13, -2, -5, -1, -4, -3, 0}
sortLexicographically(someIntegers)
return someIntegers</syntaxhighlight>
 
--> {-1, -10, -2, -3, -4, -5, -6, 0, 1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9}</syntaxhighlight>
{{output}}
--><syntaxhighlight lang="applescript">{-1, -10, -2, -3, -4, -5, -6, 0, 1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9}</syntaxhighlight>
 
=={{header|Arturo}}==
557

edits