Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Evaluate Reverse Polish Notation
Bookmark
Input
Example 1
Example 2
Example 3
Custom
tokens
=
[2, 1, +, 3, *]
tokens
2
0
1
1
+
2
3
3
*
4
stack
tokens
2
0
1
1
+
2
3
3
*
4
stack
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
token =
"2"
(number)
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
2
1
push
1
onto the stack
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
2
1
"+"
needs the top two operands
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
2
a
1
b
compute a + b
2
+
1
=
undefined
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
3
token =
"3"
(number)
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
3
3
token =
"*"
(operator)
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
3
a
3
b
compute a * b
3
*
3
=
?
pop b =
3
, then a =
3
tokens
2
0
1
1
+
2
3
3
*
4
i
stack
9
3
compute a * b
3
*
3
=
9
push
9
back onto the stack
tokens
2
0
1
1
+
2
3
3
*
4
stack
9
return
9
algo
master
.
io
Step:
Evaluate the expression left to right with a stack.
0 / 21
Input
Example 1
Example 2
Example 3
Custom
tokens
=
[2, 1, +, 3, *]
0 / 21
algo
master
.
io
Step:
Evaluate the expression left to right with a stack.