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


Python LinkedList.insert方法代码示例

本文整理汇总了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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:10,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:11,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:16,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:11,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:11,代码来源:test_linked_list.py

示例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) +
            ')')
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:12,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:12,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:13,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:13,代码来源:test_linked_list.py

示例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)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:14,代码来源:test_linked_list.py

示例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
开发者ID:Mumbleskates,项目名称:data-structures,代码行数:7,代码来源:test_linked_list.py

示例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) + ')')
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:8,代码来源:test_linked_list.py

示例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())
开发者ID:jwhite007,项目名称:DataStructures,代码行数:87,代码来源:linked_list_tests.py


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