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 HEAD AND TAIL POINTERS 1033 REM TO HEAD OF QUEUE LOCATION 1034 REM 1040 H = 5 1050 T = 5 1051 REM 1052 REM START OF MAIN SIMULATION LOOP 1053 REM 1060 FOR J3 = 1 TO 10 1061 REM 1062 REM GENERATE A RANDOM NUMBER TO DETERMINE 1063 REM AN INSERTION WHEN N <= 5 1064 REM A DELETION WHEN N >= 6 1065 REM 1070 N = INT ( RND (1) * 10 ) + 1 1080 IF N <= 5 THEN GOSUB 1900 1090 IF N >= 6 THEN GOSUB 2110 1091 REM 1092 REM PRINT QUEUE CONTENTS 1093 REM PRINT TAIL AND KEAD POINTER VALUES 1094 REM 1100 FOR J4 = 1 TO 5 1110 PRINT Q(J4); 1120 NEXT J4 1130 PRINT " TAIL AT"; T; " HEAD AT"; H 1131 REM 1132 REM END OF MAIN SIMULATION LOOP 1133 REM 1140 NEXT J3 1150 STOP 1151 REM 1152 REM I N S E R T I O N R O U T I N E 1153 REM 1154 REM CHECK TAIL AND HEAD POINTER VALUES 1155 REM 1900 IF H = T THEN GOTO 1970 1910 IF H < T THEN GOTO 2030 1920 IF T >= 1 THEN GOTO 2030 1930 IF H = 5 THEN GOTO 2080 1931 REM 1932 REM INSERT ITEM AT Q(H) 1933 REM SINCE QUEUE IS EMPTY 1934 REM 1940 Q(5) = N 1950 T = 4 1960 GOTO 2050 1970 IF T <> 0 THEN GOTO 2000 1971 REM 1972 REM RESET POINTERS TO HEAD OF QUEUE 1973 REM 1980 H = 5 1990 T = 5 1991 REM 1992 REM CHECK IF Q(T) EMPTY FOR POSSIBLE INSERT 1993 REM 2000 IF Q(T) <> -9 THEN GOTO 2080 2010 H = 5 2020 T = 5 2021 REM 2022 REM NORMAL TAIL INSERTION 2023 REM 2030 Q(T) = N 2040 T = T - 1 2050 PRINT " " 2060 PRINT "ARRIVAL" 2070 RETURN 2080 PRINT " " 2090 PRINT "OVERFLOW" 2100 RETURN 2101 REM 2102 REM D E L E T I O N R O U T I N E 2103 REM 2104 REM CHECK POINTER VALUES FOR POSSIBLE DELETE 2105 REM 2110 IF H = T THEN GOTO 2150 2120 IF H > 0 THEN GOTO 2190 2130 H = 5 2140 GOTO 2180 2150 IF H <> 0 THEN GOTO 2180 2160 H = 5 2170 T = 5 2171 REM 2172 REM DELETE FROM Q(H) IF Q(H) HAS AN ITEM 2173 REM ELSE, QUEUE IS EMPTY, I.E. UNDERFLOW 2174 REM 2180 IF Q(H) = -9 THEN GOTO 2240 2190 Q(H) = -9 2200 H = H - 1 2201 REM 2202 REM RESET POINTERS FOR NEXT DELETE 2203 REM 2210 IF H <> 0 THEN GOTO 2260 2220 H = 5 2230 RETURN 2240 PRINT " " 2250 PRINT "UNDERFLOW" 2260 RETURN 2270 END