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.
How to use it
- 1Choose what to do: infix to postfix, infix to prefix, or evaluate a postfix expression.
- 2Type the expression, e.g. (A + B) * C - D / E, or tap an example.
- 3Press Convert and read the stack table, symbol by symbol.
(A + B) * C - D / E
This is the kind of answer you get. Put these values in the boxes or type your own.
Answer
- Postfix
- AB+C*DE/-
- Prefix
- -*+ABC/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 scanned | Stack | Postfix expression | Action |
|---|---|---|---|
| ( | ( | Push '(' | |
| A | ( | A | Operand: add it to the output |
| + | (+ | A | Push '+' |
| B | (+ | AB | Operand: add it to the output |
| ) | (empty) | AB+ | Pop + to the output, then remove the '(' |
| * | * | AB+ | Push '*' |
| C | * | AB+C | Operand: add it to the output |
| - | - | AB+C* | Pop * (higher or equal precedence), then push '-' |
| D | - | AB+C*D | Operand: add it to the output |
| / | -/ | AB+C*D | Push '/' |
| E | -/ | AB+C*DE | Operand: add it to the output |
| end | (empty) | AB+C*DE/- | End: pop /, - to the output |
About the Infix to postfix converter
What it does
Converts an infix expression to postfix (Reverse Polish) or prefix notation and shows the stack after every symbol, the table ISC Computer Science expects in an answer. It can also evaluate a postfix expression, with the stack after each step.
The rules it follows
- An operand goes straight to the output.
- An operator first pops every operator on the stack with higher or equal precedence, then is pushed. ^ goes right to left, so an equal ^ stays on the stack.
- ( is pushed; ) pops operators until the matching (.
- At the end the stack is emptied into the output.
- Precedence, highest first: ^, then * / %, then + and −.
- For prefix, the expression is reversed (swapping the brackets), converted with the same stack method, and the result reversed.
Evaluating postfix
Scan left to right. Push each operand; at an operator pop two values (the second one popped is the left operand), work it out and push the result. The one value left at the end is the answer.
Common questions
Why is the second value popped the left operand?
The first value popped is the one pushed last, which is the right operand. For 8 2 − the stack holds 8 and then 2; popping gives 2 first, so the result is 8 − 2 = 6, not 2 − 8.
What is the postfix form of A + B * C?
ABC*+. The * has higher precedence than +, so B * C is worked out first and + comes last.
Do I need spaces between the letters?
No: AB+C* works as A B + C *. Use spaces between numbers (5 6 2 + *) and between names of more than one letter.
Practise on real ISC questions
- Convert the following infix notation to postfix form. ( A / B + C ) / ( D * ( E − F )2024 Specimen
- Convert the following infix notation to postfix notation: $A * (B + C / D) - E / F$2022 Specimen
- Convert the following infix expression to postfix form: $P * Q / R + (S + T)$2017
- Convert the following infix notation to postfix form: $A + ( B - C * ( D / E ) * F )$2018
- Convert the following infix notation to prefix form. $(P + Q / R) * (S + T / U) / V$2026 Improvement
- Convert the following infix notation to prefix notation. $(A - B) / C * (D + E)$2023
- Convert the following infix notation to postfix form. $(P + Q * R - S) / T * U$2024
- For the given Binary Tree, which traversal order will arrange the elements in ascending order?2025 Practice
- Convert the following infix notation to prefix form: $(X + Y) / (Z * W / V)$2020
- Convert the following infix notation to postfix form. (A*B^C) + (D*E) where B^C = $B^C$2025 Improvement
More Computer Science tools
- Boolean algebra solverSimplify any expression: the laws step by step, truth table, K-map and the logic circuit.
- Binary tree and BST toolBuild a binary search tree, rebuild a tree from two traversals, and get every traversal and fact.
- Stack and queue simulatorRun push, pop, insert and delete on a stack, queue, circular queue or dequeue, and watch the pointers move.
- Recursion visualiserWatch factorial, Fibonacci, power, GCD and sum of digits run: the calls, the call stack and the returns.
- Tower of Hanoi visualiserWatch the discs move between the pegs while the recursive calls and the call stack build up.
- Binary search tree visualiserWatch values being inserted into a binary search tree, searched for, and walked inorder, preorder and postorder.
- Binary tree traversal visualiserClick a binary tree together and watch preorder, inorder and postorder walk it, with the recursive calls on the call stack.
- Stack and queue visualiserWatch push, pop, insert and delete move top, front and rear along the array, with overflow and underflow.
- Linked list visualiserWatch nodes being added, deleted, searched, traversed and reversed, with start, p, prev and curr moving along the arrows.
- 2D array visualiserWatch row-wise, column-wise, diagonal, boundary and spiral walks number the cells of a 2D array in the order they print.
- Sorting visualiserWatch bubble, selection and insertion sort compare, swap and shift your own list, step by step.
- Linear and binary search visualiserWatch a linear or binary search look for a value in your list, and count the comparisons.