本文整理汇总了Python中LinkedList.LinkedList.add_tail方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.add_tail方法的具体用法?Python LinkedList.add_tail怎么用?Python LinkedList.add_tail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.add_tail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_duplicate_follow_up
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add_tail [as 别名]
def remove_duplicate_follow_up(LList):
this_node = LList.get_root()
result = LinkedList()
while this_node:
d = this_node.get_data()
if not result.find(d):
result.add_tail(d)
this_node = this_node.get_next()
return result
示例2: partition
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add_tail [as 别名]
def partition (LList, x):
this_node = LList.get_root()
smaller = LinkedList()
larger = LinkedList()
while this_node:
if this_node.get_data() < x:
smaller.add_tail(this_node.get_data())
else:
larger.add_tail(this_node.get_data())
this_node = this_node.get_next()
smaller.add_node(larger.get_root())
return smaller
示例3: sum
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add_tail [as 别名]
def sum(L1, L2):
node1 = L1.get_root()
node2 = L2.get_root()
result = LinkedList()
i = 0
while node1 and node2:
n1 = node1.get_data()
n2 = node2.get_data()
r = (n1+n2+i)%10
i = (n1+n2+i)/10
result.add_tail(r)
node1 = node1.get_next()
node2 = node2.get_next()
while node1:
result.add_tail(node1.get_data())
node1 = node1.get_next()
while node2:
result.add_tail(node2.get_data())
node2 = node2.get_next()
return result
示例4: LinkedList
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add_tail [as 别名]
n1 = node1.get_data()
n2 = node2.get_data()
r = (n1+n2+i)%10
i = (n1+n2+i)/10
result.add_tail(r)
node1 = node1.get_next()
node2 = node2.get_next()
while node1:
result.add_tail(node1.get_data())
node1 = node1.get_next()
while node2:
result.add_tail(node2.get_data())
node2 = node2.get_next()
return result
L1 = LinkedList()
L1.add_tail(7)
L1.add_tail(1)
L1.add_tail(6)
L2 = LinkedList()
L2.add_tail(5)
L2.add_tail(9)
L2.add_tail(2)
L = sum(L1,L2)
L.printList()
示例5: while
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add_tail [as 别名]
slow = fast = l.get_root()
s.append(slow.get_data())
while (slow and fast and fast.get_next()):
slow = slow.get_next()
s.append(slow.get_data())
fast = fast.get_next().get_next()
if fast:
s.pop()
slow = slow.get_next()
while slow:
t = s.pop()
if (slow.get_data() != t):
return False
slow = slow.get_next()
return True
list = LinkedList()
list.add_tail('A')
list.add_tail('B')
list.add_tail('C')
list.add_tail('D')
list.add_tail('E')
list.add_tail('D')
list.add_tail('C')
list.add_tail('B')
list.add_tail('A')
print palindrome(list)