Lab3

Write a C program to implement stack using arrays and demonstrate its use for balancing symbols. You may have separate functions for push(e), pop(), size(), isEmpty(), top() and display.


Balancing Symbols:

Start with an empty stack and expression P

Scan P from left to right examining one element at a time

while end of input is not reached do

if character read is not a symbol to be balanced then

ignore it

if the character is an opening symbol then

PUSH it into the stack

if it is a closing symbol then

if the stack is empty then

report an error and stop

else

a=POP the stack

if a is not the corresponding opening symbol then

report an error and stop

else

continue to read the next character

if the stack is not empty then

report an error

The symbols could be (), [], {}