adding cs235
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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
|
||||
Reference in New Issue
Block a user