本文整理汇总了Python中stack.Stack.length方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.length方法的具体用法?Python Stack.length怎么用?Python Stack.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import length [as 别名]
class VisitOrder:
stack = None
level = 0
node_list = []
def __init__( self ):
self.stack = Stack()
def make_stack( self ):
while self.stack.length() > 0:
print "self.stack.length() ==> " + str( self.stack.length() )
print "Pop the stack ---> " + str( self.stack.pop().value )
def get_node( self, node_id ):
for n in self.node_list:
#print 'get_node ' + str( n.id )
if n.id == node_id:
return n
return None
def build_tree( self, node ):
self.level = self.level + 1
print "in build_tree level : " + str( self.level )
while len( node.value ) > 0:
node.left = self.stack.pop()
build_tree( node.left )
while len( node.value ) > 0:
node.right = self.stack.pop()
build_tree( node.right )
示例2: buscaEmProfundidade
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import length [as 别名]
def buscaEmProfundidade(self, a, b):
pilha = Stack()
if (a < len(self.matriz)):
pilha.push(a)
answer = [a]
while (pilha.length() > 0):
i = pilha.pop()
j = 0
check = True
while j < self.size and check:
if (self.matriz[i][j] > -1):
if (j == b):
return True
try:
aux = answer.index(j)
except ValueError:
answer += [j]
pilha.push(i)
pilha.push(j)
check = False
j += 1
return False