本文整理汇总了Python中LinkedList.addNode方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.addNode方法的具体用法?Python LinkedList.addNode怎么用?Python LinkedList.addNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.addNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: partition
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import addNode [as 别名]
def partition(linkedList, x):
small, large = LinkedList(), LinkedList();
node = linkedList.head
while node:
if node.value < x:
small.addNode(node.value)
else:
large.addNode(node.value)
node = node.next
small.tail.next = large.head
return small
示例2: addList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import addNode [as 别名]
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
示例3: linkedlist
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import addNode [as 别名]
else:
smallEnd.next = node
smallEnd = smallEnd.next
else:
if not largeStart:
largeStart = largeEnd = node
else:
largeEnd.next = node
largeEnd = largeEnd.next
node = node.next
if smallEnd is None:
return linkedlist(largeStart)
smallEnd.next = largeStart
return LinkedList(smallStart)
if __name__ == "__main__":
nodes = [Node(i) for i in range(10)]
nodes.extend([Node(3), Node(5)])
nodes.insert(1, Node(8))
linkedlist = LinkedList()
for node in nodes:
linkedlist.addNode(node)
print linkedlist
print partitionList(linkedlist, 5)
示例4: isPalindrome
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import addNode [as 别名]
from LinkedList import *
def isPalindrome(linkedList):
newlist = []
slow, fast = linkedList.head, linkedList.head
while fast and fast.next:
newlist.append(slow.value)
slow, fast = slow.next, fast.next.next
if fast: slow = slow.next
while slow:
if slow.value != newlist.pop():
return False
slow = slow.next
return True
test = LinkedList()
test.addNode(1)
test.addNode(2)
test.addNode(3)
test.addNode(4)
test.addNode(3)
test.addNode(2)
test.addNode(1)
print(test)
print(isPalindrome(test))