本文整理匯總了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)