Question: Merge two sorted lists

Okay so my proff wrote the following procedures to sort a list and they obviosuly work. Now I want to write a procedure that can merge two sorted lists (using SelectSort). I am trying to write merge as a procedure but to no avail. Can anyone help me out?

getListSize := proc (L)

local vv; vv := Vector(L);

return LinearAlgebra[Dimension](vv)

end proc

 

swap := proc (L, i, j)

local temp, vv;

vv := Vector(L);

temp := vv[i];

vv[i] := vv[j];

vv[j] := temp;

return vv

end proc

 

getMinitemLoc := proc (L)

local i, Lsize, currentMinItem, currentMinItemLoc;

Lsize := getListSize(L); currentMinItem := L[1];

currentMinItemLoc := 1;

for i to Lsize do

if L[i] < currentMinItem then

currentMinItem := L[i];

currentMinItemLoc := i

end if

end do;

return currentMinItemLoc

end proc

 

SelectSort := proc (L)

local minItemLocation, i, vv;

vv := Vector(L);

for i to getListSize(vv)-1 do

minItemLocation := i-1+getMinitemLoc(vv[i .. getListSize(L)]);

vv := swap(vv, i, minItemLocation)

end do;

return vv

end proc

Please Wait...