Can you please rewrite this program without using class and def, The question is given below. i didn't input all the code because it's too long. i need a simple one.
Create a program that will convert an infix expression entered by the user to its equivalent prefix and postfix expression Sample Output: Enter an Infix Expression: a+b^(c^d- e/(f+g)+(h^i)^j) <input> Postfix Expression: abcd^efg+/- hi^j^+^+ <compute> Prefix Expression: +a^b+- ^cd/e+fg^^hij
class infix_to_prefix:
precedence={'^':5,'*':4,'/':4,'+':3,'-':3,'(':2,')':1}
def __init__(self):
self.items=[]
self.size=-1
def push(self,value):
self.items.append(value)
self.size+=1
def pop(self):
if self.isempty():
return 0
else:
#infix_to_prefix
precedence={'^':5,'*':4,'/':4,'+':3,'-':3,'(':2,')':1}
items=[]
size=-1
items.append(value)
size+=1
ret=1
if isempty():
ret=0
else:
Comments
Leave a comment