本文整理汇总了Python中data_structures.linked_list.LinkedList.insert方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.insert方法的具体用法?Python LinkedList.insert怎么用?Python LinkedList.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data_structures.linked_list.LinkedList
的用法示例。
在下文中一共展示了LinkedList.insert方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pop_from_one_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_pop_from_one_list(self):
"""Pop from a LinkedList with one node."""
ll = LinkedList()
ll.insert(self.insert_string)
self.assertEqual(ll.head.value, self.insert_string)
node = ll.pop()
self.assertEqual(node.value, self.insert_string)
self.assertTrue(ll.head is None)
示例2: test_insert_float_into_empty
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_insert_float_into_empty(self):
"""Insert into a LinkedList that is empty."""
ll = LinkedList()
self.assertTrue(ll.head is None)
ll.insert(self.insert_float)
self.assertEqual(ll.head.value, self.insert_float)
self.assertTrue(isinstance(ll.head.value, float))
self.assertTrue(ll.head.next is None)
示例3: test_insert_float_into_populated
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_insert_float_into_populated(self):
"""Insert into a LinkedList that is already populated with some
values
"""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
self.assertEqual(ll.head.value, self.insert_string)
ll.insert(self.insert_float)
self.assertEqual(ll.head.value, self.insert_float)
self.assertTrue(isinstance(ll.head.value, float))
self.assertEqual(ll.head.next.value, self.insert_string)
示例4: test_search_list_without_value
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_search_list_without_value(self):
"""Search a populated LinkedList for a value it doesn't contain."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
node = ll.search(self.value_not_in_list)
self.assertTrue(node is None)
示例5: test_size_of_populated_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_size_of_populated_list(self):
"""Get the size of a populated LinkedList."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
self.assertEqual(ll.head.value, self.insert_string)
self.assertEqual(ll.size(), 3)
示例6: test_str_many_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_str_many_list(self):
"""Get the string representation of a LinkedList with many values."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
self.assertEqual(ll.__str__(), '(' + "'" + self.insert_string +
"', " + str(self.insert_int) + ', ' + str(self.insert_float) +
')')
示例7: test_search_list_with_value_at_tail
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_search_list_with_value_at_tail(self):
"""Search a populated LinkedList for a value it contains at its tail."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
node = ll.search(self.insert_float)
self.assertTrue(isinstance(node, LinkedListNode))
self.assertEqual(node.value, self.insert_float)
示例8: test_remove_list_without_value
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_remove_list_without_value(self):
"""Remove from a populated LinkedList a value it doesn't contain."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
prestring = ll.__str__()
ll.remove(self.value_not_in_list)
poststring = ll.__str__()
self.assertEqual(prestring, poststring)
示例9: test_pop_from_many_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_pop_from_many_list(self):
"""Pop from a LinkedList with many nodes."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
self.assertEqual(ll.head.value, self.insert_string)
node = ll.pop()
self.assertEqual(node.value, self.insert_string)
self.assertEqual(ll.head.value, self.insert_int)
示例10: test_remove_list_with_value_at_tail
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_remove_list_with_value_at_tail(self):
"""Remove from a populated LinkedList a value it contains at its tail."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
ll.remove(self.insert_float)
expected = '(' + "'" + self.insert_string + "'" + ', ' + \
str(self.insert_int) + ')'
poststring = ll.__str__()
self.assertEqual(expected, poststring)
示例11: test_insert
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_insert():
a_list = LinkedList()
a_list.insert(1)
assert list(a_list) == [1]
assert a_list.size() == 1
示例12: test_str_one_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
def test_str_one_list(self):
"""Get the string representation of a LinkedList with one value."""
ll = LinkedList()
ll.insert(self.insert_float)
self.assertEqual(ll.__str__(), '(' + str(self.insert_float) + ')')
示例13: TestLinky
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import insert [as 别名]
class TestLinky(unittest.TestCase):
def setUp(self):
self.linky = LinkedList()
l = [1, 2, 3, 4]
for i in l:
self.linky.insert(i)
def test_insert_to_empty(self):
self.linky = LinkedList()
self.linky.insert(1)
self.assertEqual(1, self.linky.head.val)
def test_insert_to_non_empty(self):
self.linky.insert(5)
self.assertEqual(5, self.linky.head.val)
def test_pop_empty(self):
self.linky = LinkedList()
self.assertEqual(None, self.linky.pop())
def test_pop_non_empty(self):
self.assertEqual(4, self.linky.pop())
def test_size_greater_than_one(self):
self.assertEqual(4, self.linky.size())
def test_size_of_one(self):
self.linky = LinkedList()
self.linky.insert(1)
self.assertEqual(1, self.linky.size())
def test_size_of_zero(self):
self.linky = LinkedList()
self.assertEqual(0, self.linky.size())
def test_search_exists(self):
self.assertEqual(True, self.linky.search(3))
def test_search_not_exists(self):
self.assertEqual(False, self.linky.search(5))
def test_remove_head(self):
self.linky.remove(4)
self.assertListEqual([3, 2, 1], self.linky.print_me())
def test_remove_middle(self):
self.linky.remove(2)
self.assertListEqual([4, 3, 1], self.linky.print_me())
def test_print_me(self):
self.linky = LinkedList()
self.assertListEqual([], self.linky.print_me())
def test_return_0th_from_4th(self):
self.assertEqual(1, self.linky.return_kth_from_nth(0, 4))
def test_return_1st_from_4th(self):
self.assertEqual(2, self.linky.return_kth_from_nth(1, 4))
def test_return_0th_from_2nd(self):
self.assertEqual(3, self.linky.return_kth_from_nth(0, 2))
def test_return_1st_from_2nd(self):
self.assertEqual(4, self.linky.return_kth_from_nth(1, 2))
def test_partition_around_x(self):
self.linky = LinkedList()
l = [1, 2, 3, 4, 5, 6, 7, 5, 8, 9, 10]
for i in range(len(l)):
self.linky.insert(l[i])
self.linky.partition_around_x(5)
self.assertListEqual([1, 2, 3, 4, 5, 5, 10, 9, 8, 7, 6],
self.linky.print_me())
def test_rem_dups(self):
self.linky = LinkedList()
self.linky.insert(1)
self.linky.insert(1)
self.linky.insert(2)
self.linky.insert(2)
self.linky.insert(3)
self.linky.insert(3)
self.linky.rem_dups()
self.assertListEqual([3, 2, 1], self.linky.print_me())