本文整理汇总了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)
示例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