20 CLS
30 N = 5
40 DIM LA(1 TO N) AS INTEGER
50 LET Q = 1
60 LET W = 1
70 LET OPTION1 = 1
80 WHILE (OPTION1)
90 PRINT "[.................]"
100 PRINT "1 ...> PUSH"
110 PRINT "2...>POP"
120 PRINT "3...>DISPLAY"
130 PRINT "4...>EXIT"
140 PRINT "[.................]"
150 INPUT "RANGE (1 TO 4) ", X
160 SELECT CASE (X)
170 CASE (1)
180 IF Q = N THEN
190 PRINT "STACK FULL"
200 ELSE
210 PRINT "ENTER ELEMENT TO BE PUSHED ", LA(Q)
220 Q = Q + 1
230 END IF
240 CASE (2)
250 IF F = Q THEN
260 PRINT "STACK EMPTY"
270 ELSE
280 INPUT "ELEMENT TO BE POPPED ", ITEM
290 LA(N) = ITEM
300 I = 1
310 WHILE (LA(I) <> ITEM)
320 I = I + 1
340 WEND
350 IF I = N THEN
360 PRINT "ITEM NOT IN THE STACK"
370 ELSE K = I
380 J = Q - 2
390 WHILE (K <= J)
400 LA(K) = LA(K + 1)
410 K = K + 1
420 WEND
430 Q = Q - 1
440 END IF
450 END IF
460 CASE (3)
470 IF F = Q THEN
480 PRINT "EMPTY STACK"
490 ELSE
500 PRINT "STATUS"
510 FOR M = 1 TO Q - 1
520 PRINT “LA(M)”
530 NEXT M
540 END IF
550 CASE (4)
560 PRINT "END"
570 END SELECT
580 INPUT "ENTER 1 TO CONTINUE OR ENTER 0 TO STOP ", OPTION1
590 WEND
600 END
PROGRAM RESULT
0 Comments
If you have further concerns, kindly drop a comment.