Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,25 @@
|
|||
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));
|
||||
Loading…
Add table
Add a link
Reference in a new issue