本文整理汇总了Python中utils.Util.imprimir方法的典型用法代码示例。如果您正苦于以下问题:Python Util.imprimir方法的具体用法?Python Util.imprimir怎么用?Python Util.imprimir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Util
的用法示例。
在下文中一共展示了Util.imprimir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import Util [as 别名]
# 或者: from utils.Util import imprimir [as 别名]
class searchtree:
def __init__(self): #constructor of class
self.root = None
self.comparacao = 0
self.troca = 0
self.util = Util()
def insert(self,val): #insert binary search tree nodes
self.comparacao += 1
if self.root == None:
self.root = Node(val)
self.troca += 1
else:
current = self.root
self.troca += 1
while 1:
self.comparacao += 1
if val < current.info:
self.comparacao += 1
if current.left:
current = current.left
self.troca += 1
else:
current.left = Node(val)
self.troca += 1
break;
elif val > current.info:
self.comparacao += 1
self.comparacao += 1
if current.right:
self.troca += 1
current = current.right
else:
self.troca += 1
current.right = Node(val)
break;
else:
self.comparacao += 1
break
def bft(self): #Breadth-First Traversal
self.root.level = 0
queue = [self.root]
out = []
current_level = self.root.level
while len(queue) > 0:
current_node = queue.pop(0)
if current_node.level > current_level:
current_level += 1
out.append("\n")
out.append(str(current_node.info) + " ")
if current_node.left:
current_node.left.level = current_level + 1
queue.append(current_node.left)
if current_node.right:
current_node.right.level = current_level + 1
queue.append(current_node.right)
self.util.imprimir(self.util.INFO,"".join(out))
def inorder(self,node):
if node is not None:
self.inorder(node.left)
self.util.imprimir(self.util.INFO,node.info)
self.inorder(node.right)
def preorder(self,node):
if node is not None:
self.util.imprimir(self.util.INFO,node.info)
self.preorder(node.left)
self.preorder(node.right)
#.........这里部分代码省略.........