Question: Sorting procedure for lists of integers

Hi, I'm stuck on how to create a procedure, 'Arrange' that sorts a list of integers so that the numbers go from smallest to largest. So if I have a list such as: [3,6,1,9,0,4] ,

Arrange([3,6,1,9,0,4]) = [0,1,3,4,6,9]

I have a procedure that produces a sequence where we denote 'x' as the first number in the list, and returns: a list of all the numbers in the list less than x, x, a list of all the numbers greater than x.

i.e. returns: [1, 0], 3, [6, 9, 4]

Arrange := proc(L)
local L1,L2,n,x,i;
L1:=[];
L2:=[];
n:=nops(L):
if n=0 then
print('NULL')
elif n=1 then 
return L[1];
elif n>1 then
x:= L[1];

for i from 2 to n do 
if L[i] < x then
L1:=[L1[],L[i]]:
else 
L2:=[L2[],L[i]]:

end if:
end do:
end if:
return L1,x,L2;

end proc:

could anyone help on how I can expand on this to get the procedure that I want?

 

p.s. I know that there is already an inbuilt 'sort' function in Maple, but I'm trying to create the procedure myself!
 

Please Wait...