You are on page 1of 2

Experiment No: 2

Implementation of Stack, Queues, Priority Queues, DEQUEUE and Circular Queues using arrays

2.a STACK

PROBLEM DEFINITION:

Write a program to implement the operations in stack using array.

ALGORITHM:

Algorithm for main( )


Step 1: Start
Step 2: Read choice for push, pop, display and exit.
Step 2.1: If push, call push( )
Step 2.2: If pop, call pop( )
Step 2.3: If display, call display( )
Step 2.4: If exit, call exit(0)
Step 3: Stop

Algorithm for push()

Step 1: Declare all the variables.


Step 2: Read item to be pushed.
Step 3: Check (top= size-1)
Step 3.1: Print Stack Overflow
Step 4: else
Step 4.1: top++
stack[top] = item
Print inserted item

Algorithm for pop()

Step 1: Declare all the variables.


Step 2: Check (top= -1)
Step 2.1: Print Stack Underflow
Step 3: else
Step 3.1: item = stack[top]
Print deleted item
top--
Algorithm for display()

Step 1: Declare all the variables.


Step 2: Check (top= -1)
Step 2.1: Print No elements in Stack
Step 3: else
Step 3.1: Print all item

You might also like