def bodmas(exp): expr = exp.split() oper = ArrayStack() nums = ArrayStack() for a in expr: if a.isdigit() == True: nums.push(a) elif a in ['+', '-', '*', '/']: oper.push(a) else: continue while oper.isempty() == False: a = int(nums.pop()) b = int(nums.pop()) op = oper.pop() if op == '+': result = b + a if op == '-': result = b - a if op == '*': result = b * a if op == '/': result = b / a nums.push(result) return (result)
def DFS(G, a): status={} for node in G.nodes(): status[node]='U' nodes=ArrayStack() nodes.push(a) status[a]='V' while nodes.isempty()==False: pnode=nodes.pop() status[pnode]='P' print(pnode) for node in G.neighbors(pnode): if status[node]=='U': nodes.push(node) status[node]='V' return