Stacks are useful for backtracking problems (eg: navigating a maze) previous states are recorded so that algorithmic progress may occur from them at a later time
Stacks are the implementation technique used for embodying backtracking
some compilers convert the infix expressions used in programming to postfix expressions, and generate machine code to evaluate them.
In infix the operator is written between the operands:
A * B + (C - D / E)
In postfix the operator is written after the operands:
A B * C D E / - +
In postfix notation, ()s are needed. ie. the evaluation is unambiguous and does not rely on operator precedence.
Converting infix to postfix:
By hand, add ()s to all subexpressions, then move the operators to the position of the corresponding ), and delete (s. eg.
A * B + (C - D / E)
((A * B) + (C - (D / E)))
((A B* (C (D E/-+
A B* C D E/-+
Here is an algorithm that uses backtracking via a stack for converting infix to postfix: