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


Python LinkedList.generate方法代码示例

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


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

示例1: addList

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

def addList(list1, list2):
    a, b = list1.head, list2.head
    result = LinkedList()
    temp = 0
    while a and b:
        num = (a.value + b.value + temp) % 10
        result.addNode(num)
        temp = (a.value + b.value + temp) / 10
        a, b = a.next, b.next
    if a:
        result.addNode(a.value + temp)
        reuslt.tail.next = a.next
    elif b:
        result.addNode(b.value + temp)
        result.tail.next = b.next
    return result

l1, l2 = LinkedList(), LinkedList()
l1.generate(5, 0, 9)
l2.generate(6, 0, 9)
print(l1)
print(l2)
print(addList(l1, l2))

开发者ID:Haruuuko,项目名称:CTCI_5th,代码行数:27,代码来源:question2_5.py

示例2: loopBegin

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

def loopBegin(linkedList):
    slow, fast, start = linkedList.head, linkedList.head, linkedList.head
    while slow and fast:
        slow, fast = slow.next, fast.next.next
        if slow == fast: break
    while start and slow:
        start, slow = start.next, slow.next
        if start == slow: break
    return start

test = LinkedList()
test.generate(20, 0, 9)
print(test)
test.tail.next = test.head.next.next.next
print(loopBegin(test).value)

开发者ID:Haruuuko,项目名称:CTCI_5th,代码行数:19,代码来源:question2_6.py

示例3: partition

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


partition (lList, val):
	less = LinkedList()
	greater = LinkedList()
	
	# add elements as read to the greater and lesser linked lists
	# combine the linked lists for the ending thing. 

ll = LinkedList()
ll.generate(10, 20, 30, 40, 50, 60, 70, 80 90)
print(ll)
partition(ll, ll.head.value)
print(ll)
开发者ID:soham-shah,项目名称:coding_practice,代码行数:17,代码来源:2_4.py


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