本文整理汇总了Python中tree.Node.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Node.insert方法的具体用法?Python Node.insert怎么用?Python Node.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Node
的用法示例。
在下文中一共展示了Node.insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lookup
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import insert [as 别名]
def test_lookup():
root = Node(8)
root.insert(3)
root.insert(10)
assert root.lookup(8) == (root, None)
assert root.lookup(3) == (root.left, root)
assert root.lookup(10) == (root.right, root)
示例2: Node
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import insert [as 别名]
import datetime
from tree import Node
from file import search, delete
tree = Node('')
with open('input.txt') as f:
for line in f:
tree.insert(line)
print("1. Print tree\n2. Search node\n3. Delete node\n4. Exit")
ans = True
while ans:
ans = raw_input("What would you like to do? ")
if ans == "1":
print("Tree:")
tree.printTree()
elif ans == "2":
print("Searching node...")
data = raw_input("Enter node data: ")
a = datetime.datetime.now()
print "Node found: ", tree.search(data).data
b = datetime.datetime.now()
print "Found in file: ", search(data)
c = datetime.datetime.now()
print "Search in tree time: ", b - a
print "Search in file time: ", c - b
elif ans == "3":
print("Deletion node...")
data = raw_input("Enter node data: ")
tree.delete(data)
delete(data)
示例3: test_insert
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import insert [as 别名]
def test_insert():
root = Node(8)
root.insert(3)
root.insert(10)
assert root.left.data == 3
assert root.right.data == 10
示例4: test_delete
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import insert [as 别名]
def test_delete():
root = Node(8)
root.insert(3)
root.delete(3)
root.delete(8)