Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,23 @@
declare
proc {BubbleSort Arr}
proc {Swap I J}
Arr.J := (Arr.I := Arr.J) %% assignment returns the old value
end
IsSorted = {NewCell false}
MaxItem = {NewCell {Array.high Arr}-1}
in
for until:@IsSorted do
IsSorted := true
for I in {Array.low Arr}..@MaxItem do
if Arr.I > Arr.(I+1) then
IsSorted := false
{Swap I I+1}
end
end
MaxItem := @MaxItem - 1
end
end
Arr = {Tuple.toArray unit(10 9 8 7 6 5 4 3 2 1)}
in
{BubbleSort Arr}
{Inspect Arr}

View file

@ -0,0 +1,25 @@
declare
local
fun {Loop Xs Changed ?IsSorted}
case Xs
of X1|X2|Xr andthen X1 > X2 then
X2|{Loop X1|Xr true IsSorted}
[] X|Xr then
X|{Loop Xr Changed IsSorted}
[] nil then
IsSorted = {Not Changed}
nil
end
end
in
fun {BubbleSort Xs}
IsSorted
Result = {Loop Xs false ?IsSorted}
in
if IsSorted then Result
else {BubbleSort Result}
end
end
end
in
{Show {BubbleSort [3 1 4 1 5 9 2 6 5]}}