0% found this document useful (0 votes)
216 views

Implement A Stack Data Structure in Cobol

This document implements a stack data structure in COBOL. It uses an array AA with 100 elements indexed by I to represent the stack. The program displays a menu and allows the user to push or pop items from the stack by incrementing or decrementing the index I. When I reaches 0 or a negative number, it displays that the stack is empty.

Uploaded by

sati1987
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
216 views

Implement A Stack Data Structure in Cobol

This document implements a stack data structure in COBOL. It uses an array AA with 100 elements indexed by I to represent the stack. The program displays a menu and allows the user to push or pop items from the stack by incrementing or decrementing the index I. When I reaches 0 or a negative number, it displays that the stack is empty.

Uploaded by

sati1987
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

STACK IN COBOL AIM: IMPLEMENT A STACK DATA STRUCTURE IN COBOL ****** ***************************** Top of Data ******************************* ******* IDENTIFICATION

DIVISION. PROGRAM-ID. MAC. DATA DIVISION. WORKING-STORAGE SECTION. 01 A. 05 AA PIC X(5) OCCURS 100 TIMES INDEXED BY I. 01 B PIC X(5). 01 C PIC 9. PROCEDURE DIVISION. 0001. SET I TO 0. 00A. DISPLAY "MENU". DISPLAY "1.PUSH". DISPLAY "2.POP". DISPLAY "3.POP ALL" DISPLAY "4.EXIT". ACCEPT C. IF C = 1 PERFORM 0002 DISPLAY "ITEM PUSHED " ELSE IF C = 2 PERFORM 0003 ELSE IF C = 3 PERFORM 0003 UNTIL I = 0 ELSE STOP RUN. GO 00A. 0002. SET I UP BY 1. IF I > 100 DISPLAY "STACK FULL". DISPLAY "ENTER VALUE ". ACCEPT B. MOVE B TO AA ( I ). 0003. MOVE AA ( I ) TO B. DISPLAY "ITEM POPPED:" B. SET I DOWN BY 1. IF I = 0 OR I < 0 DISPLAY "EMPTY STACK". ****** **************************** Bottom of Data ***************************** ******* //Compatible with all compilers & version SAMPLE OUTPUT

MENU 1.PUSH 2.POP 3.POPALL 4.EXIT 1 ENTER VALUE

28 ITEM PUSHED MENU 1.INSERT 2.RETRIVE 3.EXIT 1 ENTER VALUE 19 ITEM PUSHED MENU 1.INSERT 2.RETRIVE 3.EXIT 3 ITEM POPPED: 19 ITEM POPPED: 28 EMPTY STACK

You might also like