1000 DIM Q(5) 1001 REM 1002 REM INITIALIZE QUEUE TO EMPTY STATE 1003 REM 1010 FOR J2 = 1 TO 5 1020 Q(J2) = -9 1030 NEXT J2 1031 REM 1032 REM INITIALIZE TAIL TO HEAD OF QUEUE 1033 REM 1040 T = 5 1041 REM 1042 REM START OF MAIN SIMULATION LOOP 1043 REM 1050 FOR J2 = 1 TO 15 1051 REM 1052 REM GENERATE A RANDOM NUMBER TO DETERMINE 1053 REM AN INSERTION WHEN N <= 5 1054 REM A DELETION WHEN N >= 6 1055 REM 1060 N = INT ( RND (1) * 10 ) + 1 1070 PRINT "NUMBER="; N; 1080 IF N <= 5 THEN GOSUB 1170 1090 IF N >= 6 THEN GOSUB 1240 1091 REM 1092 REM PRINT QUEUE CONTENTS 1093 REM PRINT TAIL POINTER VALUE 1094 REM 1100 PRINT " QUEUE="; 1110 FOR J3 = 1 TO 5 1120 PRINT Q(J3); 1130 NEXT J3 1140 PRINT " TAIL="; T 1141 REM 1142 REM END OF MAIN SIMULATION LOOP 1143 REM 1150 NEXT J2 1160 STOP 1161 REM 1162 REM I N S E R T I O N R O U T I N E 1163 REM 1164 REM WHEN T = 0 QUEUE IS FULL, I.E. OVERFLOW 1165 REM ELSE, INSERT N AT TAIL AND DECREMENT TAIL 1166 REM 1170 IF T = 0 THEN GOTO 1220 1180 PRINT " INSERTION"; 1190 Q(T) = N 1200 T = T - 1 1210 RETURN 1220 PRINT " OVERFLOW "; 1230 RETURN 1231 REM 1232 REM D E L E T I O N R O U T I N E 1233 REM 1234 REM WHEN T = 5 QUEUE IS EMPTY, I.E. UNDERFLOW 1235 REM ELSE, DELETE N AT HEAD OF QUEUE 1236 REM AND MOVE REMAINING ITEMS TOWARD HEAD 1237 REM 1240 IF T = 5 THEN GOTO 1350 1250 PRINT " DELETION "; 1260 T = T + 1 1270 FOR J4 = 5 TO T STEP -l 1280 IF J4 = 1 THEN GOTO 1330 1290 J5 = J4 - 1 1300 Q(J4) = Q(J5) 1310 NEXT J4 1320 RETURN 1330 Q(1) = -9 1340 RETURN 1350 PRINT " UNDERFLOW"; 1360 RETURN 1370 END