10 ! INSERT SORT ON THE 71B -Ver. A- Rev. 9/23/86 20 DESTROY ALL 30 OPTION BASE 1 40 N1=127 !! total number of records is 2^n-1 (any value for n is OK) 50 N9=5 ! ! number of fields per record 60 DIM G(N9),H(N9),I(N9) ! G(n) = size or length of each field 70 ! ! H(n) = beginning byte positions in record string 80 ! ! I(n) = ending byte positions in record string 90 G(1)=10 ! length of first field 100 G(2)=20 ! length of 2nd field 110 G(3)=30 ! length of 3rd field 120 G(4)=35 ! length of 4th field 130 G(5)=15 ! length of 5th field 140 N7=0 ! ! initialize number of bytes per record 150 Y=0 ! ! initialize field positions for H(n) and I(n) arrays 160 Z=0 ! ! initialize longest-field variable 170 FOR X=1 TO N9 ! count from 1 to the number of fields 180 H(X)=Y+1 ! ! H(n) = beginning byte position in record string 190 I(X)=Y+G(X) ! ! I(n) = ending byte position in record string 200 N7=N7+G(X) ! ! sum no. of bytes in each field to get total bytes/record 210 Y=Y+G(X) ! ! increment Y to next field position 220 IF ZCHR$(126) THEN 730 430 FOR X=1 TO N9 ! ! count from 1 to the no. of fields 440 INPUT J$(X) ! ! input data for each field 450 IF UPRC$(J$(X))="QUIT" THEN 740 ! ! if no more input, end of program 460 J$(X)=J$(X)&X3$[1,G(X)-LEN(J$(X))] ! append blanks to each input so that 470 ! ! each field is full-size for filing 480 NEXT X ! ! end of loop 490 B$="" ! ! initialize data record string 500 FOR X=1 TO N9 ! start loop to fill B$ with the field data input as above 510 B$=B$&J$(X) ! ! fill B$ 520 NEXT X ! ! end of loop 530 P1=N2 ! set up a temporary control pointer 540 P2=N3 ! set temporary increment/decrement variable for control pointer 550 IF B$[H(1),I(1)]>A$[P1+H(1),P1+I(1)] THEN P1=P1+P2 ELSE P1=P1-P2 560 ! If input field is greater than data in corresponding position in file, 570 ! increment the control pointer. If input field is less than or equal 580 ! to the data in the file, decrement the control pointer. 590 P2=P2/2 ! next increment or decrement will be 1/2 of the prior one 600 IF P2>N7/4 THEN 550 ! when the increment/decrement pointer falls to 1/4 610 ! ! the size of a single record, the search has been 620 ! ! exhausted and the temporary control pointer will 630 ! ! be between a file record which is greater than or 640 ! ! equal to the input data, and a file record which 650 ! ! is less than the input data. 660 P1=P1+N7/2 ! adjust temporary control pointer upward to the 670 ! ! beginning point of the file record which is 680 ! ! greater than or equal to the input data 690 A$[P1+N7+1,N0]=A$[P1+1,N0-N7] ! shift file string upward by the length 700 ! ! of one record to prepare for insertion 710 A$[P1+1,P1+N7]=B$ ! insert new record in place in A$ 720 GOTO 410 ! go and input more new data 730 DISP "FILE FULL-PROGRAM DONE" 740 END