Sorting algorithms/Shell sort: Difference between revisions

Content added Content deleted
(Added a V implementation)
(Added AppleScript implementation)
Line 241: Line 241:
abcdefghiijklmnopqrstuvwxyz
abcdefghiijklmnopqrstuvwxyz
</pre>
</pre>

=={{header|AppleScript}}==

<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. Either o's lst or theList can be returned if preferred. They and the input list are all the same object.
end ShellSort

set aList to {60, 73, 11, 66, 6, 77, 41, 97, 59, 45, 64, 15, 91, 100, 22, 89, 77, 59, 54, 61}
ShellSort(aList)
return aList
--> {6, 11, 15, 22, 41, 45, 54, 59, 59, 60, 61, 64, 66, 73, 77, 77, 89, 91, 97, 100}</lang>

=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}