Stack Appln
Stack Appln
Stack Application
• Arithmetic expression evaluation:
– An important application of stacks is in parsing.
– In high level languages, infix notation cannot be
used to evaluate expressions.
– A common technique is to convert an infix
notation into postfix notation, then evaluating it.
• Java bytecode is interpreted on (virtual) stack based
processor.
Infix to postfix
• Step 1 : Scan the Infix Expression from left to right.
• Step 2 : If the scanned character is an operand, append it with final Infix to Postfix
string.
• Step 3 : Else,
– Step 3.1 : If the precedence order of the scanned(incoming) operator is greater than the
precedence order of the operator in the stack (or the stack is empty or the stack contains a
Infix to Postfix conversion
2. a operand append a
-
3. - operator push (
4. b operand append ab
1. f operand append f
)
2. - operator push -
+
3. ) operator push fe )
-
4. e operand append
5. + operator push fed
6. d operand append fed+ -