Infix To Postfix Programmed in Python
Infix To Postfix Programmed in Python
class stack:
def __init__(self):
self.stack = []
def remove(self):
end = self.stack[-1]
self.stack.pop(-1)
return end
def __len__(self):
return len(self.stack)
def print(self):
pro = ", ".join(self.stack)
print(f"Stack: {pro}")
# the func
def convert(self):
for char in self.infix:
if char == "(":
pass
#self.b_depth += 1
for i in range(len(self.operator_stack)):
self.postfix = self.postfix + " " +
self.operator_stack.remove()
return self.postfix
# example input
# print(converter("((15 ÷ (7 − (1 + 1))) × 3) − (2 + (1 + 1))").convert())