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


Python Stack.isempty方法代码示例

本文整理汇总了Python中stack.Stack.isempty方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.isempty方法的具体用法?Python Stack.isempty怎么用?Python Stack.isempty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stack.Stack的用法示例。


在下文中一共展示了Stack.isempty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_BST

# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import isempty [as 别名]
    def print_BST(binarynode):
        """Prints a subset of a BST without recursion.
        This function will print the value at node and the value at
        all of node's children in sorted order.
        """

        stack = Stack()
        curr = binarynode
        print "<",
        while not stack.isempty() or curr:
            if curr:
                stack.push(curr)
                curr = curr.left
            else:
                curr = stack.pop()
                currval = curr.val
                curr = curr.right
                print str(currval),
                if not stack.isempty() or curr:
                    print ',',
        print ">"
开发者ID:kendricktang,项目名称:python_problems,代码行数:23,代码来源:binarysearchtree.py

示例2: print_BST_test

# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import isempty [as 别名]
    def print_BST_test(binarynode):
        """This should be identical to print_BST in every way
        except it adds the elements to a list and returns it
        """

        stack = Stack()
        curr = binarynode
        lst = []
        while not stack.isempty() or curr:
            if curr:
                stack.push(curr)
                curr = curr.left
            else:
                curr = stack.pop()
                currval = curr.val
                curr = curr.right
                lst.append(currval)
        return lst
开发者ID:kendricktang,项目名称:python_problems,代码行数:20,代码来源:binarysearchtree.py

示例3: Stack

# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import isempty [as 别名]
from stack import Stack

s = Stack(20)
for i in range(3):
    s.push(i)
print s.pop()
print s.isempty()
print s.isfull()



开发者ID:TomTsong,项目名称:Python-stack-queue,代码行数:10,代码来源:stacktest.py


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