24 lines
403 B
Python
24 lines
403 B
Python
|
from collections import deque
|
||
|
|
||
|
|
||
|
op_prec = {
|
||
|
'*': 3,
|
||
|
'/': 3,
|
||
|
'%': 3,
|
||
|
'+': 2,
|
||
|
'-': 2,
|
||
|
}
|
||
|
|
||
|
|
||
|
def shunt(tokens):
|
||
|
tokens = deque(tokens)
|
||
|
output = deque()
|
||
|
operators = deque()
|
||
|
while tokens:
|
||
|
token = tokens.pop()
|
||
|
if token.isdigit():
|
||
|
output.append(token)
|
||
|
elif token in op_prec:
|
||
|
operators.append(token)
|
||
|
return output, operators
|