Question: merge sort algorithm help needed

Hi i am trying to code the Merge sort algorithm in maple but i've reached a point where i can't progress further. Any assistance would be greatly appriciated.

This is what i have done so far

FIRST ATTEMPT:

restart:
with(ListTools):
L := rtable(1..6,random(1..50));
n:=convert(L,'list');
E:=[LengthSplit(n,nops(n)/2)];

for j from 1 to nops(E) do
F:=[LengthSplit(E[j],1)];
d:=[]:
smallest:=op(F[1]):

for i from 1 to nops(F) do
if op(F[i]) < smallest then
 smallest:=op(F[i])
else NULL
fi:
od:
t:=smallest:
d:=[op(d),t]:
F:=d:

print(F):
od:

SECOND ATTEMPT.

restart:
with(ListTools):
L := rtable(1..6,random(1..50));
n:=convert(L,'list');

E:=[LengthSplit(n,nops(n)/2)];
q:=E[1]:
w:=E[2]:

for i from 1 to nops(q)-1 do
if q[i] > q[i+1] then
 (q[i],q[i+1]):=(q[i+1],q[i]);
fi:
od:


for i from 1 to nops(w)-1 do
if w[i] > w[i+1] then
 (w[i],w[i+1]):=(w[i+1],w[i]);
fi:
od:
t:=[q,w];

 

                     n:=      [44, 5, 38, 37, 3, 15]
                     E:=    [[44, 5, 38], [37, 3, 15]]
                      t:=   [[5, 38, 44], [3, 15, 37]]

i have sorted the list and now i am trying to get maple to check each element in each list and compare it the other looking for the smallest value. Once it identifies the smallest value i want it to put it into a new list then do the same process until the new list contains all the values from smallest to the largest.

 

This is the closest i came for idetifying the smallest element but it dosn't work.
 

for i from 1 to nops(t)-1 do
if t[i,i] < t[i+1,i] then
small:=t[i,i]:
else
small:=t[i+1,i]:
fi:od:
small;

g:=[op(g),small];

 

Please Wait...