Workspace Postfix To Infix
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Postfix to Infix visualizer

Learn Postfix to Infix with a step-by-step Stacks & Queues visualizer, JavaScript source code and a worked example. Practice operations and expressions.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 6Execution step
Reference example · JavaScript
Inspect reference input
{
  "input": "abc*+",
  "reverse": false
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
input,reverse
},s)=>{
let a=[];
for(let x of reverse?[...input].reverse():input){
if(/[a-z]/.test(x))a.push(x);
else{
let p=a.pop(),q=a.pop();
a.push(reverse?"("+p+x+q+")":"("+q+x+p+")")
}
s("Combine expression operands",{
Stack:a
})
}
return a[0]
};

Execution canvas

Active Changed
STEP 1

Combine expression operands

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Stack1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Stacks & Queues · Operations and expressions

Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.

Example input

{
  "input": "abc*+",
  "reverse": false
}

Execution steps

  1. Combine expression operands

Computed output

"(a+(b*c))"
JavaScript reference implementation
const solve = ({
  input,reverse
},s)=>{
  let a=[];
  for(let x of reverse?[...input].reverse():input){
    if(/[a-z]/.test(x))a.push(x);
    else{
      let p=a.pop(),q=a.pop();
      a.push(reverse?"("+p+x+q+")":"("+q+x+p+")")
    }
    s("Combine expression operands",{
      Stack:a
    })
  }
  return a[0]
};

Continue learning

Practice related DSA questions in the same topic.