Stack Applications
Bracket checking
One example of application of a stack is in checking that bookend semantics such as brackets are properly matched. That is if you have an expresion containing various brackets, the function would tell you if the brackets are correctly placed and matched.
int bracketcheck(char expr[]);
returns true if expr is a string where (), {} and [] brackets are properly matched. false if not.
Postfix expression calculator
The way we write expressions uses infix notation. In other words, all operations look like A operator B (operator is "in" the middle of the expression). In order to change the order of operations, we must use (). Order of operations also matter
Another way to write expressions is to use postfix expression. All operations look like A B operator (the operator is after the operands) The advantage of postfix expressions is that brackets are not needed and order of operators are not needed. Example: infix
(1+2) - 3* (4+5)
equivalent postfix:
1 2 + 3 4 5 + * -
Some calculators actually use postfix notation for entry.