Question
Create a suite of routines to manipulate a stack of char. An
array of char should be used as stack storage, and an
int as a stack pointer.
These must be defined in the file containing
the suite. Functions to push, pop, examine the top of stack,
and to determine if the stack is empty must be provided. The
push, pop and examine functions must return '\0' if
unsuccessful. Push must return the character pushed if
successful.
Use the stack routines to implement an infix to postfix
converter. Only +, -, * and / will appear as operators in the
infix expression.
The algorithm is:
repeat
read symbol
if symbol is an operand then
add to postfix expression
else begin
while (stack not empty) and
(stack_top has greater or equal precedence than this operator)
pop stack onto postfix expression
push this symbol onto stack
end
until end of infix expression
while (stack not empty)
pop stack onto postfix expression
Answer