Question: Help with

Question:Help with

Jimmy19001 128 Maple

I have tried to programme a bubble sort procedure below and i'm a bit stuck and not sure where i've gone wrong. Many thanks.

 bubblesort:=proc(C)
local n,o,r,k,i:
n:=rtable_dims(C):
o:=rhs(n):
r:=lhs(n):
for i from r to o - 1 do
if C[i] > C[i+1] then
(C[i], C[i+1] ) := (C[i+1], C[i]);
else
(C[i], C[i+1] ) := (C[i], C[i+1] );
fi:
od:
return(C);
end proc:

 C:=rtable(1..6,random(1..50));
bubblesort(C);

C:=[44 5 38 37 3 15]
[5 38 37 3 15 44]

What i can see is that the procedure is only going through it once and not again, so i believe my mistake is in line 6 of the procedure.

Any help would be appriciated!!

Please Wait...