DECLARE SUB MERGE (A%(), NA%, B%(), NB%, C%())
DEFINT A-Z
CLS : NA = 3: DIM A(NA): DATA 0,2,4
FOR K = 0 TO NA - 1: READ A(K): PRINT A(K); : NEXT K: PRINT
NB = 4: DIM B(NB): DATA 1,3,5,7
FOR K = 0 TO NB - 1: READ B(K): PRINT B(K); : NEXT K: PRINT
DIM C(NA + NB)
MERGE A(), NA, B(), NB, C()
FOR K = 0 TO NA + NB - 1: PRINT C(K); : NEXT K
END
SUB MERGE (A(), NA, B(), NB, C())
JA = 0: JB = 0
FOR JC = 0 TO NA + NB
IF JA < NA AND JB < NB THEN
IF A(JA) < B(JB) THEN
C(JC) = A(JA): JA = JA + 1: GOTO M1
ELSE
C(JC) = B(JB): JB = JB + 1: GOTO M1
END IF
END IF
IF JA = NA AND JB < NB THEN
C(JC) = B(JB): JB = JB + 1: GOTO M1
END IF
IF JA < NA AND JB = NB THEN
C(JC) = A(JA): JA = JA + 1
END IF
M1:
NEXT JC
END SUB