本文整理汇总了Python中linkedlist.LinkedList.add_to_back方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.add_to_back方法的具体用法?Python LinkedList.add_to_back怎么用?Python LinkedList.add_to_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linkedlist.LinkedList
的用法示例。
在下文中一共展示了LinkedList.add_to_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_last_item_point_to_none
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_last_item_point_to_none(self):
'''Item at the back has None as next pointer'''
ll = LinkedList()
ll.add_to_back(0, 23)
assert ll.back.next == None
ll.add_to_back(123, 234)
assert ll.back.next == None
示例2: test_add_back_appends_item
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_add_back_appends_item(self):
'''Adding to the back of the list multiple times does not remove items.
Instead the list is appended with the new item'''
ll = LinkedList()
ll.add_to_back(12, 345)
ll.add_to_back(14, 34)
assert ll.back.key == 14
assert ll.back.prev.key == 12
示例3: test_add_back_multiple_equal_items
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_add_back_multiple_equal_items(self):
'''Adding the same item to the back of the list multiple times creates
different linked list objects with the same item'''
ll = LinkedList()
ll.add_to_back(12)
ll.add_to_back(12)
assert ll.back.key == ll.back.prev.key
assert ll.back != ll.back.prev
示例4: test_remove_all_items_deletes_front_and_back
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_remove_all_items_deletes_front_and_back(self):
ll = LinkedList()
item1 = ll.add_to_back("lkjh")
item2 = ll.add_to_back([1,2,3])
ll.remove(item2)
ll.remove(item1)
assert ll.front == None
assert ll.back == None
示例5: test_remove_updates_back_if_necessary
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_remove_updates_back_if_necessary(self):
'''Removing back updates back'''
ll = LinkedList()
item1 = ll.add_to_back(123)
item2 = ll.add_to_back("lkj")
assert ll.back == item2
ll.remove(item2)
assert ll.back == item1
示例6: test_non_empty_list_has_length
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_non_empty_list_has_length(self):
ll = LinkedList()
ll.add_to_front(123)
assert ll.length == 1
ll.add_to_back(345)
assert ll.length == 2
ll.add_to_front(987)
assert ll.length == 3
示例7: test_add_to_back_next
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_add_to_back_next(self):
'''Adding to back makes previous back item the item before the new
back'''
ll = LinkedList()
key1 = 123
key2 = 1233
ll.add_to_back(key1)
ll.add_to_back(key2)
assert ll.back.prev.key == key1
assert ll.back.prev.next.key == key2
示例8: test_in_filter_remove_selective
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_in_filter_remove_selective(self):
ll = LinkedList()
item1 = ll.add_to_back(1, 345)
item2 = ll.add_to_back(5, 15151551)
item3 = ll.add_to_back(7, 234267)
item4 = ll.add_to_back(1, 907525)
item5 = ll.add_to_back(7, 789235)
ll.in_filter(lambda x,y: x==1)
assert ll.length == 2
assert ll.front == item1
assert ll.back == item4
示例9: test_add_to_empty_back_gives_new_front
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_add_to_empty_back_gives_new_front(self):
'''Adding an item to the back of an empty list also creates a front
that is equal to the back item'''
ll = LinkedList()
key = 12
value = "asd"
ll.add_to_back(key, value)
assert ll.back.key == key
assert ll.front.key == key
assert ll.back.value == value
assert ll.front.value == value
assert ll.front == ll.back
示例10: test_in_filter_applies_func_to_all_items
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_in_filter_applies_func_to_all_items(self):
ll = LinkedList()
items = [ll.add_to_back(123, 345),
ll.add_to_back("", 2345),
ll.add_to_back([1,2,3], 234)]
ll.in_filter(lambda x, y: True)
ll_current = ll.front
assert ll.length == 3
i = 0
while ll_current:
assert ll_current == items[i]
ll_current = ll_current.next
i += 1
示例11: test_filter_remove_selective
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_filter_remove_selective(self):
ll = LinkedList()
item1 = ll.add_to_back(1, 345)
item2 = ll.add_to_back(5, 15151551)
item3 = ll.add_to_back(7, 234267)
item4 = ll.add_to_back(1, 907525)
item5 = ll.add_to_back(7, 789235)
ll2 = ll.filter(lambda x,y: x==1)
assert ll2.length == 2
assert ll2.front.key == item1.key
assert ll2.front.value == item1.value
assert ll2.back.key == item4.key
assert ll2.back.value == item4.value
示例12: test_remove
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_remove(self):
'''Removing an item brings adjacent items together'''
ll = LinkedList()
key1 = 141
key2 = 123
key3 = 552
ll.add_to_back(key1)
ll.add_to_back(key2)
ll.add_to_back(key3)
front = ll.front
back = ll.back
middle = front.next
ll.remove(middle)
assert front.next == back
assert back.prev == front
示例13: test_swap_non_edge_items
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_swap_non_edge_items(self):
ll = LinkedList()
item1 = ll.add_to_back(5151, 91951)
item2 = ll.add_to_back(235151, 91951)
item3 = ll.add_to_back(512351, 91951)
item4 = ll.add_to_back(510951, 91951)
item5 = ll.add_to_back(51747451, 91951)
ll.swap(item2, item4)
assert item1.next.key == item4.key
assert item4.next == item3
assert item3.next == item2
assert item2.next == item5
assert item5.prev == item2
assert item2.prev == item3
assert item3.prev == item4
assert item4.prev == item1
示例14: test_removed_item_has_no_parent
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_removed_item_has_no_parent(self):
'''Removing an item also removes any references from the item to the
list'''
ll = LinkedList()
litem = ll.add_to_back(list())
assert litem.parent()
ll.remove(litem)
assert litem.parent == None
示例15: test_swap_same_no_effect
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_back [as 别名]
def test_swap_same_no_effect(self):
ll = LinkedList()
item1 = ll.add_to_back(123, 91284)
item2 = ll.add_to_back(51515, 192)
assert ll.front == item1
assert ll.back == item2
assert ll.length == 2
ll.swap(item1, item1)
assert ll.front == item1
assert ll.back == item2
assert ll.length == 2