⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
tokens = [“1”,“2”,”+”,“3”,”*”,“4”,”-”]
Output: 5
push 1 [1] push 2 [1, 2] operand so pop last two and do operation 1 + 2 = 3 push result to stack [3] push 3 to stack [3, 3] operand so pop last two numbers and do operation 3 * 3 = 9 push result to stack [9] push 4 to the stack [9, 4] operand so pop last two and do operation 9 - 4 = 5 push 5 to the stack [5] input tokens has reached the end so return result value
conditions
- when we see an operand pop the last two values and perform operation
- once done performing operation push back to result stack
- continue until we’ve reached the end of the input stack