本文整理汇总了Python中stack.Stack.returnStack方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.returnStack方法的具体用法?Python Stack.returnStack怎么用?Python Stack.returnStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.returnStack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RailExpress
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import returnStack [as 别名]
class RailExpress():
def __init__(self, express):
self.fontExpress = express
self.railExpress = []
self.size = len(express)
self.stack = Stack(self.size)
self.queue = Queue(self.size)
self.level = {'+': 1, '-': 1, '*': 2, '/': 2, '(': 3, ')': 3}
self.operators = ['+', '-', '*', '/', '(', ')']
self.makeRailExpress()
def makeRailExpress(self):
for i in self.fontExpress:
if i in self.operators:
if i is self.operators[-1]:
ele = self.stack.pop()
while ele is not self.operators[-2]:
self.queue.push(ele)
ele = self.stack.pop()
if self.stack.isEmpty():
break
elif i is self.operators[-2]:
self.stack.push(i)
else:
if not self.stack.isEmpty():
while self.stack.returnFristEle() is not self.operators[-2] and self.level[self.stack.returnFristEle()] >= self.level[i]:
ele = self.stack.pop()
self.queue.push(ele)
if self.stack.isEmpty():
break
self.stack.push(i)
else:
self.queue.push(i)
if not self.stack.isEmpty():
stack = self.stack.returnStack()
stack.reverse()
self.queue.returnQueue().extend(stack)