Learn Evaluate Reverse Polish Notation 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.
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
[
"2",
"1",
"+",
"3",
"*"
]
Execution steps
Process 2
Process 1
Process +
Process 3
Process *
Computed output
9
JavaScript reference implementation
const solve = (a,s)=>{
let st=[];
for(let x of a){
if(["+","-","*","/"].includes(x)){
let b=st.pop(),c=st.pop();
st.push(x==="+"?c+b:x==="-"?c-b:x==="*"?c*b:Math.trunc(c/b))
}else st.push(+x);
s("Process "+x,{
Stack:st
})
}
return st[0]
};