Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stack:
- def __init__(self):
- self._stek = []
- def isEmpty(self):
- if len(self._stek) != 0:
- return False
- return True
- def push(self, element):
- self._stek.append(element)
- def pop(self):
- return self._stek.pop()
- def top(self):
- return self._stek[-1]
- def prikazi(self):
- for i in self._stek:
- print str(i) + " ",
- print
- def __len__(self):
- return len(self._stek)
- niz = Stack()
- infix = raw_input()
- postfix = ""
- for i in infix:
- if "0" <= i <= "9":
- postfix += i
- else:
- if ((len(niz)>0) and (i=="+" or i=="-") and (niz.top()=="*" or niz.top()=="/")):
- while len(niz) > 0:
- postfix += str(niz.pop())
- elif (len(niz)>0 and ((i=="-" and (niz.top()=="+" or niz.top()=="-")) or (i=="+" and niz.top()=="-"))):
- postfix += str(niz.pop())
- elif (len(niz)>0 and ((i=="/" and (niz.top()=="*" or niz.top()=="/")) or (i=="/" and niz.top()=="/") or (i=="*" and niz.top()=="/"))):
- postfix += str(niz.pop())
- niz.push(i)
- while len(niz) > 0:
- postfix += str(niz.pop())
- print postfix
- input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement