هدا هو الواجب
Write a program to convert fully parenthesized
infix notation to suffix notation.
Fully parenthesized infix example:
((a+B)*(c/d))$
(the $ is an end marker)
The suffix for the above:
ab+cd/*
In suffix notation, the operator follows
the operands.
Your program:
- all operands will be single letters.
- a $ will indicate the end of the string.
- no embedded blanks.
Algorithm:
read a character from the input.
- if it is a $ you are done - see below.
- if it is a open paren, ignore it.
- if it is an operand, write it to the output.
- if it is an operator (+-*/), push it on a stack.
- if it is a close paren, pop the top of stack to output
use getchar() for input and putchar(int) for output.
the stack: an array with a corresponding index like:
char stack[20];
int stx = 0;
to push: put the character into stack[stx] then increment
stx.
to pop to output: decrement stx and putchar(stack[stx]);
when done, check to see that the stack is empty (stx==0).
if not, this is an error situation.
what does all this mean? suffix notation can be directly
executed by a computer whereas infix cannot. converting
input to suffix can be the first step to executing an
expression. some advanced calculators require you to
enter your expressions in suffix notation.
