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


Python Node.insert方法代码示例

本文整理汇总了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)
开发者ID:kuantumk,项目名称:cc150Python,代码行数:9,代码来源:tree-test.py

示例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)
开发者ID:Helga-Helga,项目名称:ADS,代码行数:33,代码来源:main.py

示例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
开发者ID:kuantumk,项目名称:cc150Python,代码行数:8,代码来源:tree-test.py

示例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)
开发者ID:kuantumk,项目名称:cc150Python,代码行数:7,代码来源:tree-test.py


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