本文整理汇总了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 ">"
示例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
示例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()