Polish Notation

How to check that a Postfix notation is valid or not?For example :a+b is wrong postfix
Thanks in advance.
Last edited on
Use a stack.
Push numbers until you find an operator. Once you find an operator, pop two values, use them as operands and push the result. If at any point the stack underflows, the expression is invalid. If the input is neither a operator or a number, the expression is invalid. If there are no more tokens and the stack has more than one element, the expression is invalid.

Do a search. The algorithm is very simple.
http://www.c4learn.com/data-structure/algorithm-evaluation-of-postfix-expression/
Topic archived. No new replies allowed.