Sort a list of object identifiers: Difference between revisions
m
→{{header|AppleScript}}: Minor change to sort in vanilla version.
m (added Category:Sorting) |
m (→{{header|AppleScript}}: Minor change to sort in vanilla version.) |
||
Line 116:
*)
on ShellSort(theList, l, r)
script o
property lst : theList
Line 123:
set listLength to (count theList)
if (listLength > 1) then
-- Convert negative and/or transposed range indices.
set stepSize to listLength div 2▼
if (l < 0) then set l to listLength + l + 1
if (r < 0) then set r to listLength + r + 1
if (l > r) then set {l, r} to {r, l}
-- Do the sort.
repeat while (stepSize > 0)
repeat with i from (
set currentValue to item i of o's lst
repeat with j from (i - stepSize) to
set thisValue to item j of o's lst
if (currentValue < thisValue) then
Line 142 ⟶ 148:
end if
return -- nothing. The input list has been sorted in place.
end ShellSort
property sort : ShellSort
-- Test code: sort items 1 thru -1 (ie. all) of a list of strings, treating numeric portions numerically.
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
end considering
return theList</lang>
|