Sorting algorithms/Stooge sort: Difference between revisions

no edit summary
No edit summary
Line 1,049:
 
</lang>
 
=={{header|Maple}}==
<lang Maple>swap := proc(arr, a, b)
local temp := arr[a];
arr[a] := arr[b];
arr[b] := temp;
end proc:
 
stoogesort:= proc(arr, start_index, end_index)
local cur;
if (arr[end_index] < arr[start_index]) then
swap(arr, start_index, end_index);
end if;
if end_index - start_index > 1 then
cur := trunc((end_index - start_index + 1)/3);
stoogesort(arr, start_index, end_index - cur);
stoogesort(arr, start_index + cur, end_index);
stoogesort(arr, start_index, end_index - cur);
end if;
return arr;
end proc:
 
 
arr := Array([4, 2, 6, 1, 3, 7, 9, 5, 8]):
stoogesort(arr, 1, numelems(arr));</lang>
{{out}}
<pre>
[1, 2, 3, 4, 5, 6, 7, 8, 9]
</pre>
 
 
=={{header|Mathematica}}==
Anonymous user