Sorting algorithms/Shell sort: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed whitespace and indentations.) |
No edit summary |
||
Line 1,484: | Line 1,484: | ||
print(i) |
print(i) |
||
end</lang> |
end</lang> |
||
=={{header|Maple}}== |
|||
<lang>shellsort := proc(arr) |
|||
local n, gap, i, val, j; |
|||
n := numelems(arr): |
|||
gap := trunc(n/2): |
|||
while (gap > 0) do #notice by 1 error |
|||
for i from gap to n by 1 do |
|||
val := arr[i]; |
|||
j := i; |
|||
while (j > gap and arr[j-gap] > val) do |
|||
arr[j] := arr[j-gap]; |
|||
j -= gap; |
|||
end do; |
|||
arr[j] := val; |
|||
end do; |
|||
gap := trunc(gap/2); |
|||
end do; |
|||
end proc; |
|||
arr := Array([17,3,72,0,36,2,3,8,40,0]); |
|||
shellsort(arr); |
|||
arr;</lang> |
|||
{{Out|Output}} |
|||
<pre>[0,0,2,3,3,8,17,36,40,72]</pre> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |