本文整理汇总了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))
示例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)
示例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)