Question: please write comments to explain how this function is using a Stack! from pythonds.basic import Stack def infixToPostfix(infixexpr): prec = {} prec[*] = 3 prec[/]

please write comments to explain how this function is using a Stack!
from pythonds.basic import Stack def infixToPostfix(infixexpr): prec = {} prec["*"] = 3 prec["/"] = 3 prec["+"] = 2 prec["-"] = 2 prec["("] = 1 opStack Stack() postfixList = [] tokenlist = infixexpr.split() for token in token list: if token in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" or token in "0123456789": postfixList.append(token) elif token == '(: opStack.push(token) elif token == : topToken = opStack.pop() while topToken != ' (': postfixList.append(topToken) top Token = opStack.pop() else: while (not opStack.isEmpty()) and in (prec[opStack. peek 0 ] >= prec[token]): postfixList.append (opStack, pop()) opStack.push(token) while not opStack.is Empty(): postfixList.append(opStack.pop() return ".join(postfixList) print(infixTo Postfix("A *=B + C * D:)) print(infixToPostfix("' ( A + B ) * C D E * F G ="))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
