Prashnikaप्रश्निका

Infix to postfix converter

Convert an infix expression to postfix (Reverse Polish) or prefix notation the way ISC Computer Science marks it, with the stack after every symbol - or evaluate a postfix expression step by step.

What to do

Operators: + - * / % and ^ (power). Brackets ( ) [ ] { } work. Operands can be letters, names or numbers.

Try: (A + B) * C - D / EA + B * C ^ D ^ Eprefix of (P + Q) * (R - S)evaluate 5 6 2 + * 12 4 / -evaluate AB+C*

Answer

Postfix
ABCDE^^*+
Prefix
+A*B^C^DE

Stack table

Scan left to right. An operand goes straight to the output. An operator first pops every operator of higher or equal precedence (^ is right to left, so an equal ^ stays), then is pushed. ( is pushed; ) pops up to its (. At the end the stack is emptied.

Symbol scannedStackPostfix expressionAction
A(empty)AOperand: add it to the output
++APush '+'
B+ABOperand: add it to the output
*+*ABPush '*'
C+*ABCOperand: add it to the output
^+*^ABCPush '^'
D+*^ABCDOperand: add it to the output
^+*^^ABCDPush '^'
E+*^^ABCDEOperand: add it to the output
end(empty)ABCDE^^*+End: pop ^, ^, *, + to the output

Practise on real ISC questions

More Computer Science tools

  • Boolean algebra solver Simplify any expression: the laws step by step, truth table, K-map and the logic circuit.
  • Binary tree and BST tool Build a binary search tree, rebuild a tree from two traversals, and get every traversal and fact.

All study tools ›