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


Python LinkedList.add_node方法代码示例

本文整理汇总了Python中linkedlist.LinkedList.add_node方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.add_node方法的具体用法?Python LinkedList.add_node怎么用?Python LinkedList.add_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在linkedlist.LinkedList的用法示例。


在下文中一共展示了LinkedList.add_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_addition

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_node [as 别名]
 def test_addition(self):
   l_list = LinkedList()
   l_list.add_node(1)  
开发者ID:JoeDevelops,项目名称:python_data_structures_with_tests,代码行数:5,代码来源:test_linkedlist.py

示例2: timings

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_node [as 别名]
def timings():
    ll = LinkedList()
    bst = BST()
    avl = AVL()

    ll_add = []
    bst_add = []
    avl_add = []

    ll_search = []
    bst_search = []
    avl_search = []

    for items in range(500,5500,500):
        wordlist = create_word_list(items)
        
        ll = LinkedList()
        before = time.time()
        for i in xrange(items):
            ll.add_node(wordlist[i])
        after = time.time()
        ll_add.append(after - before)
    
        random_indices = np.random.random_integers(0,items,5)
        temp = []
        for i in xrange(len(random_indices)):
            before = time.time()
            iterative_search(ll, wordlist[random_indices[i]]) 
            after = time.time()
            temp.append(after - before)
        ll_search.append(sum(temp)/len(temp))
    
        bst = BST()
        before = time.time()
        for i in xrange(items):
            bst.insert(wordlist[i])
        after = time.time()
        bst_add.append(after - before)

        temp = []
        for i in xrange(len(random_indices)):
            before = time.time()
            bst.find(wordlist[random_indices[i]])
            after = time.time()
            temp.append(after - before)
        bst_search.append(sum(temp)/len(temp))

        avl = AVL()
        before = time.time()
        for i in xrange(items):
            avl.insert(wordlist[i])
        after = time.time()
        avl_add.append(after - before)
        
        temp = []
        for i in xrange(len(random_indices)):
            before = time.time()
            avl.find(wordlist[random_indices[i]])
            after = time.time()
            temp.append(after - before)
        avl_search.append(sum(temp)/len(temp))
    
    plt.subplot(1,2,1)
    plt.plot(ll_add, "r")
    plt.plot(bst_add, "g")
    plt.plot(avl_add, "b")
    plt.subplot(1,2,2)
    plt.plot(ll_search, "r")
    plt.plot(bst_search, "g")
    plt.plot(avl_search, "b")
    plt.show()
    plt.close()
    
    return ll_add, ll_search, bst_add, bst_search, avl_add, avl_search
开发者ID:tkchris93,项目名称:ACME,代码行数:76,代码来源:solutions.py


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