Question: sorting

Question:sorting

Jabz 433 Maple

Hi i am trying to code a procedure which sorts a list such that the smallest element is the first element and the largest element is the second elemnt then the next smallest element is the third element and the next largest element is the fourth element. For example:

 

L:=[ 2, 3, 5, 2, 7, 9 ]:
 

sorted:= [ 2, 9, 2, 7, 3, 5] :
 

this is what i have coded so far how do i make the process continue??
 

sort(L);
                       [2, 2, 3, 4, 4, 5, 5, 5, 6, 6]
Largesmall:=proc(L)
local small, large,Alt, i:
small:=L[1]:
large:=L[1]:
Alt:=[]:
for i from 1 to nops(L) do
if L[i] < small then small:=L[i] fi:
if L[i] > large then large:=L[i] fi:
od:
Alt:=[op(small),op(large)]:
print('smallest',small):
print('largest',large):
return(Alt):
end proc:
Largesmall(L);
                                 smallest, 2
                                 largest, 6
                                   [2, 6]
 

Any help would be greatly appriciated

Thanks in advance

Please Wait...