1 MERGE "MERGE.BAS"

10 CLEAR 12000:DEFINT A-Z:DIM IS$(1000),V(1000)
  :GOSUB 32000


20 OPEN "I",1,"TRANSFER"
30 LINE  INPUT  # 1,PI$:LINE  INPUT  # 1,PS$
40 CLOSE 1


50 OPEN "I",1,PI$,PI%:OPEN "R",2,PS$,PS%
60 INPUT  # 1,TN,HN,F
70 N=TN-1
80 FOR X=1 TO N:INPUT  # 1,V(X):NEXT :CLOSE 1
90 FOR J=1 TO N
100 GOSUB 200
110 NEXT :CLOSE 2


120 CLS:PRINT @ 468,"SORT IS IN PROGRESS"
130 GOSUB 240


140 CLS:PRINT @ 468,"SORT COMPLETE. SAVING FILES"
150 OPEN "O",1,PI$
160 WRITE # 1,TN,HN,F
170 FOR X=1 TO N:PRINT # 1,V(X):NEXT :CLOSE 1


180 CLS:PRINT @ 468,"ALL OPERATIONS COMPLETE"
190 PRINT @ 596,"RETURNING TO MAIN MENU":CLEAR 50:RUN "ICS.BAS":END


200 JR = J : JD = 0 ' JR=INT((J-1)/25)+1:JD=J-25*INT((J-1)/25)-1
210 FIELD 2, 10 AS N$ ' FIELD 2,JD*10ASD$,10ASN$
220 GET 2,JR:IS$(J)=N$
230 RETURN 


240 M=N
250 M=INT(M/2)
260 IF M=0 THEN RETURN 
270 K=N-M:J=1
280 I=J
290 L=I+M
300 IF IS$(ABS(V(I)))>IS$(ABS(V(L))) THEN 330
310 J=J+1:IF J>K THEN 250
320 GOTO 280
330 T=V(I):V(I)=V(L):V(L)=T:I=I-M
340 IF I<1 THEN 310
350 GOTO 290


999 END
