本文整理匯總了Python中LinkedList.LinkedList.get_root方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.get_root方法的具體用法?Python LinkedList.get_root怎麽用?Python LinkedList.get_root使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.get_root方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: partition
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import get_root [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
示例2: detectLoop
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import get_root [as 別名]
#!/usr/bin/python
from LinkedList import LinkedList
def detectLoop(l):
if l.get_size()<=0:
return False
slow = fast = l.get_root()
while (slow and fast and fast.get_next()):
slow = slow.get_next()
fast = fast.get_next().get_next()
if slow == fast:
fast = l.get_root()
while (slow and fast):
slow = slow.get_next()
fast = fast.get_next()
if slow == fast:
return slow
list = LinkedList()
list.add_tail('A')
list.add_tail('B')
list.add_tail('C')
list.add_tail('D')
list.add_tail('E')
list.get_root().get_next().get_next().get_next().get_next().set_next(list.get_root().get_next().get_next())
point = detectLoop(list)
print point.get_data()