• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python SinglyLinkedList.SinglyLinkedList类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList的典型用法代码示例。如果您正苦于以下问题:Python SinglyLinkedList类的具体用法?Python SinglyLinkedList怎么用?Python SinglyLinkedList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_list_as_generator

    def test_list_as_generator(self):

        singlyLinkedListObject = SinglyLinkedList()
        inputList = range(10,100,10)
        singlyLinkedListObject.populate(inputList)
        for index, data in enumerate(singlyLinkedListObject):
            self.assertTrue(data == inputList[index], "Data mismatch. Expected data: %s, Got: %s" %(inputList[index], data))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:7,代码来源:SinglyLinkedListTests.py


示例2: method1

    def method1(self):
        '''
        1. Go to the centre of the list using the slow and fast pointer approach
        2. Create another reversed list starting from the second half
        3. Compare this new list with the original list head and stop when the new list hits None
        :return: Boolean
        '''
        centreOfLinkedList = self.singlyLinkedListObject.returnCentreOfTheLinkedList()
        if centreOfLinkedList is None:
            # print "Empty List is a palindrome"
            return True

        newHalfList = SinglyLinkedList()
        newHalfList.populateNewListStartingFromALinkedListNode(centreOfLinkedList.nextPointer)

        #Reversing
        ReverseASinglyLinkedList.Solution().reverseOriginalList_Iterative(newHalfList)

        originalListCurrentNode = self.singlyLinkedListObject.head
        for dataFromSecondHalf in newHalfList:
            if originalListCurrentNode.data != dataFromSecondHalf:
                # print "Not a palindrome"
                return False
            originalListCurrentNode = originalListCurrentNode.nextPointer

        # print "Linked List is a palindrome"
        return True
开发者ID:prab-pip,项目名称:IntPrep,代码行数:27,代码来源:TwoDotSeven_CheckIfSinglyLinkedListisAPalindrome.py


示例3: test_append_when_list_is_empty

    def test_append_when_list_is_empty(self):
        singlyLinkedListObject = SinglyLinkedList()
        inputVal = 10
        singlyLinkedListObject.appendToListUsingTail(inputVal)
        outputList = singlyLinkedListObject.returnLinkedListAsList()
        outputVal = outputList[0]

        self.assertTrue(inputVal == outputVal, "Expected a tail value of: %s, Got: %s" %(inputVal, outputVal))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:8,代码来源:SinglyLinkedListTests.py


示例4: test_reverse_a_list_with_two_elements

    def test_reverse_a_list_with_two_elements(self):
        givenList = SinglyLinkedList()
        inputList = [10, 20]
        givenList.populate(inputList)

        s = Solution()

        s.printReverseUsingRecursion(givenList.head)
开发者ID:prab-pip,项目名称:IntPrep,代码行数:8,代码来源:Test_ReverseASinglyLinkedList.py


示例5: test_reverse_a_list_with_many_elements

    def test_reverse_a_list_with_many_elements(self):
        givenList = SinglyLinkedList()
        inputList = range(10,101,10)
        givenList.populate(inputList)

        s = Solution()

        s.printReverseUsingRecursion(givenList.head)
开发者ID:prab-pip,项目名称:IntPrep,代码行数:8,代码来源:Test_ReverseASinglyLinkedList.py


示例6: test_populate

    def test_populate(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = range(20)
        singlyLinkedListObject.populate(inputList)
        outputList = singlyLinkedListObject.returnLinkedListAsList()

        self.assertTrue(inputList == outputList, "Input List: %s and Output List: %s don't match" %(inputList, outputList))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:8,代码来源:SinglyLinkedListTests.py


示例7: test_yield_reverse_list_with_three_elements

    def test_yield_reverse_list_with_three_elements(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = [1, 2, 3]
        singlyLinkedListObject.populate(inputList)

        s = Solution()

        for i in s.yieldListDataInReversedOrderUsingRecursion(singlyLinkedListObject.head):
            print i
开发者ID:prab-pip,项目名称:IntPrep,代码行数:10,代码来源:Test_ReverseASinglyLinkedList.py


示例8: test_reverse_an_empty_list

    def test_reverse_an_empty_list(self):
        givenList = SinglyLinkedList() # Because it's an empty list, no need to populate it

        s = Solution()
        outputLinkedList = SinglyLinkedList()
        s.returnReversedListUsingRecursion(givenList.head, outputLinkedList)
        inputList = []
        expectedList = inputList
        returnedList = outputLinkedList.returnLinkedListAsList()
        self.assertTrue(expectedList == returnedList, "Expected: %s, Got: %s" %(expectedList, returnedList))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:10,代码来源:Test_ReverseASinglyLinkedList.py


示例9: test_length_of_list_after_list_change_operations

    def test_length_of_list_after_list_change_operations(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = range(10)
        singlyLinkedListObject.populate(inputList)

        expectedLength = len(inputList)

        actualLength = len(singlyLinkedListObject)

        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))

        singlyLinkedListObject.deleteHead()

        expectedLength -= 1

        actualLength = len(singlyLinkedListObject)

        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))

        singlyLinkedListObject.insertAtHead(200)
        expectedLength += 1

        actualLength = len(singlyLinkedListObject)

        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))


        singlyLinkedListObject.insertAtHead(200)
        expectedLength += 1

        actualLength = len(singlyLinkedListObject)

        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:34,代码来源:SinglyLinkedListTests.py


示例10: test_length_of_list_with_many_elements

    def test_length_of_list_with_many_elements(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = range(100000)
        singlyLinkedListObject.populate(inputList)

        expectedLength = len(inputList)

        actualLength = len(singlyLinkedListObject)

        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:11,代码来源:SinglyLinkedListTests.py


示例11: test_return_centre_of_list_with_many_even_elements

    def test_return_centre_of_list_with_many_even_elements(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = range(40000)
        singlyLinkedListObject.populate(inputList)

        centreIndex = (len(inputList)-1)/2
        expectedCentre = inputList[centreIndex]

        actualCentre = singlyLinkedListObject.returnCentreOfTheLinkedList()
        self.assertTrue(expectedCentre == actualCentre.data, "Expected centre if linked list: %s, Got: %s" %(expectedCentre, actualCentre))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:11,代码来源:SinglyLinkedListTests.py


示例12: test_delete_head_of_empty_list_more_than_once

    def test_delete_head_of_empty_list_more_than_once(self):
        singlyLinkedListObject = SinglyLinkedList()

        singlyLinkedListObject.deleteHead()
        self.assertTrue(singlyLinkedListObject.isHeadNone(), "Head of empty list must be None")

        singlyLinkedListObject.deleteHead()
        self.assertTrue(singlyLinkedListObject.isHeadNone(), "Head of empty list must be None")

        singlyLinkedListObject.deleteHead()
        self.assertTrue(singlyLinkedListObject.isHeadNone(), "Head of empty list must be None")
开发者ID:prab-pip,项目名称:IntPrep,代码行数:11,代码来源:SinglyLinkedListTests.py


示例13: test_add_without_carry_basic_case_both_lists_empty

    def test_add_without_carry_basic_case_both_lists_empty(self):
        firstList = SinglyLinkedList()
        secondList = SinglyLinkedList()
        outputList = SinglyLinkedList()

        s = Solution(firstList, secondList, outputList)
        s.addTwoNonReversedIntegersAsLinkedListsAndCreateNewList()

        outputValue = outputList.returnLinkedListAsList()
        expectedValue = []

        self.assertTrue(outputValue == expectedValue, "Expected: %s, Got: %s" %(expectedValue, outputValue))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:12,代码来源:Test_TwoDotFive_AddTwoNonReversedIntegersAsLinkedLists.py


示例14: test_returnNodeAtBeginingOfLinkedListLoop

    def test_returnNodeAtBeginingOfLinkedListLoop(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = range(1,12)
        singlyLinkedListObject.populate(inputList)

        s = Solution(singlyLinkedListObject)

        # Insert a loop at 4th position
        singlyLinkedListObject.tail.nextPointer = singlyLinkedListObject.head.nextPointer.nextPointer.nextPointer

        s.returnNodeAtBeginingOfLinkedListLoop()
开发者ID:prab-pip,项目名称:IntPrep,代码行数:12,代码来源:Test_TwoDotSix_ReturnNodeAtBeginingOfLinkedListLoop.py


示例15: test_add_without_carry_basic_case_second_list_empty_first_list_has_more_than_one_element

    def test_add_without_carry_basic_case_second_list_empty_first_list_has_more_than_one_element(self):
        firstList = SinglyLinkedList()
        inputValue = range(10)
        firstList.populate(inputValue)

        secondList = SinglyLinkedList()

        s = Solution(firstList, secondList)

        returnLinkedList = s.addTwoReversedIntegersAsLinkedListsAndCreateNewList()
        outputValue = returnLinkedList.returnLinkedListAsList()
        expectedValue = inputValue
        self.assertTrue(outputValue == expectedValue, "Expected: %s, Got: %s" %(expectedValue, outputValue))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:13,代码来源:Test_TwoDotFive_AddTwoReversedIntegersAsLinkedLists.py


示例16: test_changing_list_length_during_insert_at_head_operation

    def test_changing_list_length_during_insert_at_head_operation(self):
        singlyLinkedListObject = SinglyLinkedList()

        expectedLength = 0
        actualLength = len(singlyLinkedListObject)
        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))

        inputList = range(10)
        for data in inputList:
            singlyLinkedListObject.insertAtHead(data)

            actualLength = len(singlyLinkedListObject)
            expectedLength += 1  # Because a new element has been added to the list.
            self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:14,代码来源:SinglyLinkedListTests.py


示例17: test_delete_head_of_list_with_one_item

    def test_delete_head_of_list_with_one_item(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = [1]
        singlyLinkedListObject.populate(inputList)

        singlyLinkedListObject.deleteHead()
        self.assertTrue(singlyLinkedListObject.isHeadNone(), "Now that the only element in the list is deleted, Head of empty list must be None")

        singlyLinkedListObject.deleteHead()
        self.assertTrue(singlyLinkedListObject.isHeadNone(), "Now that the only element in the list is deleted, Head of empty list must be None")
开发者ID:prab-pip,项目名称:IntPrep,代码行数:11,代码来源:SinglyLinkedListTests.py


示例18: test_changing_list_length_during_delete_head_operation

    def test_changing_list_length_during_delete_head_operation(self):
        singlyLinkedListObject = SinglyLinkedList()

        inputList = range(10)
        singlyLinkedListObject.populate(inputList)

        expectedLength = len(inputList)
        actualLength = len(singlyLinkedListObject)
        self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))

        for data in inputList:
            singlyLinkedListObject.deleteHead()

            actualLength = len(singlyLinkedListObject)
            expectedLength -= 1  # Because a new element has been added to the list.
            self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:16,代码来源:SinglyLinkedListTests.py


示例19: test_delete_head_with_one_element_list

    def test_delete_head_with_one_element_list(self):
        singlyLinkedListObject = SinglyLinkedList()
        singlyLinkedListObject.populate([1])

        singlyLinkedListObject.deleteHead()
        outputList = singlyLinkedListObject.returnLinkedListAsList()
        self.assertTrue(len(outputList) == 0, "After deleting the only element in the list, Output List must be empty")
开发者ID:prab-pip,项目名称:IntPrep,代码行数:7,代码来源:SinglyLinkedListTests.py


示例20: test_add_without_left_over_carry_both_lists_have_unequal_items

    def test_add_without_left_over_carry_both_lists_have_unequal_items(self):
        firstList = SinglyLinkedList()
        secondList = SinglyLinkedList()
        outputList = SinglyLinkedList()

        firstList.populate([7,1,6,9])
        secondList.populate([5,9,2])

        s = Solution(firstList, secondList, outputList)
        s.addTwoNonReversedIntegersAsLinkedListsAndCreateNewList()

        outputValue = outputList.returnLinkedListAsList()
        expectedValue = [7,7,6,1]
        self.assertTrue(outputValue == expectedValue, "Expected: %s, Got: %s" %(expectedValue, outputValue))
开发者ID:prab-pip,项目名称:IntPrep,代码行数:14,代码来源:Test_TwoDotFive_AddTwoNonReversedIntegersAsLinkedLists.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python MyRequestsClass.MyRequests类代码示例发布时间:2022-05-24
下一篇:
Python xmlSet.setUp函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap