Sorting algorithms/Shell sort: Difference between revisions
m
→{{header|AppleScript}}: Tidied.
m (→{{header|AppleScript}}: Tidied.) |
|||
Line 445:
=={{header|AppleScript}}==
<lang applescript>
-- Algorithm: Donald Shell, 1959.
on ShellSort(theList, l, r) -- Sort items l thru r of theList.▼
set listLength to (count theList)
if (listLength < 2) then return
▲on ShellSort(theList, l, r)
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}
-- The list as a script property to allow faster references to its items.
script o
property lst : theList
end script
set
▲ -- Convert negative and/or transposed range indices.
repeat while (stepSize > 0)▼
▲ repeat with j from (i - stepSize) to l by -stepSize
▲ if (currentValue < thisValue) then
▲ set item (j + stepSize) of o's lst to thisValue
▲ set j to j + stepSize
end repeat▼
end repeat
end repeat
return -- nothing
end ShellSort
property sort : ShellSort
--
local aList
set aList to {
sort(aList, 1, -1) -- Sort
return aList</lang>
{{output}}
<lang applescript>{
=={{header|ARM Assembly}}==
|