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


Python LinkedList.printLinkedList方法代码示例

本文整理汇总了Python中LinkedList.printLinkedList方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.printLinkedList方法的具体用法?Python LinkedList.printLinkedList怎么用?Python LinkedList.printLinkedList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkedList的用法示例。


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

示例1: swapPairs

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import printLinkedList [as 别名]
import pdb

class Solution:
    # @param A : head node of linked list
    # @return the head node in the linked list
    def swapPairs(self, A):
        start = LinkedList.ListNode("dummy")
        start.next = A
        current = start

        while current.next and current.next.next:
            current.next = self.swapNodes(current.next, current.next.next)
            current = current.next.next
        return start.next
    
    def swapNodes(self, A, B):
        A.next = B.next
        B.next = A
        return B

import LinkedList
A = LinkedList.getRandomLinkedList(11, 20)
LinkedList.printLinkedList(A)
sol= Solution()
B = sol.swapPairs(A)
LinkedList.printLinkedList(B)
开发者ID:karandevgan,项目名称:Algorithms,代码行数:28,代码来源:SwapNodes.py

示例2: Solution

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import printLinkedList [as 别名]
                # Node to which reversed list has to be joined
                dummy_head = start
            start = start.next
            m -= 1
            n -= 1
        # Node form which list has to be reversed
        prev_start = start
        prev = None
        while n != 0:
            temp = start.next
            start.next = prev
            prev = start
            start = temp
            n -= 1
        # Join the current node to the next of the node from which list was reversed
        prev_start.next = start

        # If whole list is reversed
        if head == None:
            head = prev
        else:
            dummy_head.next = prev
        
        return head
        

A = LinkedList.getRandomLinkedList(10)
LinkedList.printLinkedList(A)
sol = Solution()
head = sol.reverseBetween(A, 6,9)
LinkedList.printLinkedList(head)
开发者ID:karandevgan,项目名称:Algorithms,代码行数:33,代码来源:ReverseLinkedList2.py

示例3: Solution

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import printLinkedList [as 别名]
        elif B is None:
            return A

        while A is not None and B is not None:
            if A.val < B.val:
                C.next = A
                A = A.next
            else:
                C.next = B
                B = B.next
            C = C.next
        
        while A is not None:
            C.next = A
            A = A.next
            C = C.next
        
        while B is not None:
            C.next = B
            B = B.next
            C = C.next
        
        return head.next

import LinkedList
A = LinkedList.getRandomLinkedList(13,20)
LinkedList.printLinkedList(A)

C = Solution().sortList(A)

LinkedList.printLinkedList(C)
开发者ID:karandevgan,项目名称:Algorithms,代码行数:33,代码来源:SortLinkedList.py

示例4: partition

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import printLinkedList [as 别名]
    # @param B : integer
    # @return the head node in the linked list
    def partition(self, A, B):
        start_node = LinkedList.ListNode("dummy")
        start_node.next = A
        head = start_node
        
        start_node_greater = LinkedList.ListNode("dummy")
        head_greater = start_node_greater

        while A is not None:
            if A.val >= B:
                start_node_greater.next = A
                start_node_greater = start_node_greater.next
                start_node.next = A.next
            else:
                start_node = A
            A = start_node.next
            start_node_greater.next = None   


        if head_greater.next is not None:
            start_node.next = head_greater.next

        return head.next

A = LinkedList.getRandomLinkedList(10, 20)
LinkedList.printLinkedList(A)
B = 3
sol = Solution()
LinkedList.printLinkedList(sol.partition(A,B))
开发者ID:karandevgan,项目名称:Algorithms,代码行数:33,代码来源:PartitionLinkedList.py


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