本文整理汇总了Python中stack.Stack.print_stack方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.print_stack方法的具体用法?Python Stack.print_stack怎么用?Python Stack.print_stack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.print_stack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import print_stack [as 别名]
def main(args):
print "Parse Tree..."
if ( len( args ) < 2 ):
print "Usage ./parse_tree.py 'List of arguments in string'"
sys.exit(-1)
print "Arguments:[ " + args[1] + " ]"
tokens = args[1].split()
z = Node()
z.left = z
z.right = z
stack = Stack()
stack.print_stack()
root = None
for token in tokens:
print token
x = Node()
x.value = token
# If the token is an operator. Pop and set the right link
# then pop and set the left link then push the token on the stack.
# Otherwise, push the token on to the stack.
if token == '+' or token == '*':
x.right = stack.pop()
print "Poping " + x.right.value + " from the stack and set to right link of " + token
x.left = stack.pop()
print "Poping " + x.left.value + " from the stack and set to left link of " + token
print "Pushing " + str( x.value ) + " to the stack"
stack.push( x )
print "stack after the push..."
stack.print_stack()
root = x
stack.print_stack()
traverse( root );