当前位置: 首页>>代码示例>>Python>>正文


Python Stack.print_stack方法代码示例

本文整理汇总了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 );
开发者ID:Ross-Marshall,项目名称:Algorithms-Robert-Sedgewick,代码行数:42,代码来源:parse_tree.py


注:本文中的stack.Stack.print_stack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。