Sort a list of object identifiers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
(Added AppleScript.) |
||
Line 106: | Line 106: | ||
1.3.6.1.4.1.11150.3.4.0.1 |
1.3.6.1.4.1.11150.3.4.0.1 |
||
</pre> |
</pre> |
||
=={{header|AppleScript}}== |
|||
===Vanilla=== |
|||
Place the call to the sort handler in a <tt>considering numeric strings</tt> statement. |
|||
<lang applescript>(* Shell sort |
|||
Algorithm: Donald Shell, 1959. |
|||
*) |
|||
on ShellSort(theList) |
|||
script o |
|||
property lst : theList |
|||
end script |
|||
set listLength to (count theList) |
|||
if (listLength > 1) then |
|||
set stepSize to listLength div 2 |
|||
repeat while (stepSize > 0) |
|||
repeat with i from (1 + stepSize) to listLength |
|||
set currentValue to item i of o's lst |
|||
repeat with j from (i - stepSize) to 1 by -stepSize |
|||
set thisValue to item j of o's lst |
|||
if (currentValue < thisValue) then |
|||
set item (j + stepSize) of o's lst to thisValue |
|||
else |
|||
set j to j + stepSize |
|||
exit repeat |
|||
end if |
|||
end repeat |
|||
if (j < i) then set item j of o's lst to currentValue |
|||
end repeat |
|||
set stepSize to (stepSize / 2.2) as integer |
|||
end repeat |
|||
end if |
|||
return -- nothing. |
|||
end ShellSort |
|||
-- Test code: |
|||
set theList to {"1.3.6.1.4.1.11.2.17.19.3.4.0.10", "1.3.6.1.4.1.11.2.17.5.2.0.79", "1.3.6.1.4.1.11.2.17.19.3.4.0.4", ¬ |
|||
"1.3.6.1.4.1.11150.3.4.0.1", "1.3.6.1.4.1.11.2.17.19.3.4.0.1", "1.3.6.1.4.1.11150.3.4.0"} |
|||
considering numeric strings |
|||
ShellSort(theList) |
|||
end considering |
|||
return theList</lang> |
|||
{{output}} |
|||
<pre>{"1.3.6.1.4.1.11.2.17.5.2.0.79", "1.3.6.1.4.1.11.2.17.19.3.4.0.1", "1.3.6.1.4.1.11.2.17.19.3.4.0.4", "1.3.6.1.4.1.11.2.17.19.3.4.0.10", "1.3.6.1.4.1.11150.3.4.0", "1.3.6.1.4.1.11150.3.4.0.1"}</pre> |
|||
===ASObjC=== |
|||
Use the <tt>localizedStandardCompare:</tt> string comparison method. |
|||
<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later |
|||
use framework "Foundation" |
|||
set theList to {"1.3.6.1.4.1.11.2.17.19.3.4.0.10", "1.3.6.1.4.1.11.2.17.5.2.0.79", "1.3.6.1.4.1.11.2.17.19.3.4.0.4", ¬ |
|||
"1.3.6.1.4.1.11150.3.4.0.1", "1.3.6.1.4.1.11.2.17.19.3.4.0.1", "1.3.6.1.4.1.11150.3.4.0"} |
|||
set theArray to current application's class "NSMutableArray"'s arrayWithArray:(theList) |
|||
set theDescriptor to current application's class "NSSortDescriptor"'s sortDescriptorWithKey:("self") ¬ |
|||
ascending:(true) selector:("localizedStandardCompare:") |
|||
tell theArray to sortUsingDescriptors:({theDescriptor}) |
|||
return theArray as list</lang> |
|||
{{output}} |
|||
<pre>{"1.3.6.1.4.1.11.2.17.5.2.0.79", "1.3.6.1.4.1.11.2.17.19.3.4.0.1", "1.3.6.1.4.1.11.2.17.19.3.4.0.4", "1.3.6.1.4.1.11.2.17.19.3.4.0.10", "1.3.6.1.4.1.11150.3.4.0", "1.3.6.1.4.1.11150.3.4.0.1"}</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |