本文整理匯總了Python中LinkedList.LinkedList.reverse方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.reverse方法的具體用法?Python LinkedList.reverse怎麽用?Python LinkedList.reverse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.reverse方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testReverse
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import reverse [as 別名]
def testReverse():
my_linked_list = LinkedList()
for i in range(0, 10):
my_linked_list.append(random.randint(0,9999))
print my_linked_list
my_linked_list.reverse()
print my_linked_list
示例2: testReverse
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import reverse [as 別名]
def testReverse(self):
ll = LinkedList()
ll.addNode(1)
ll.addNode(2)
ll.addNode(3)
ll.addNode(4)
self.assertEqual(str(ll), 'LinkedList [ 1->2->3->4 ]')
self.assertEqual(ll.reverse(), 'LinkedList [ 4->3->2->1 ]')
示例3: reverse_list_test
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import reverse [as 別名]
def reverse_list_test(self):
"""Test the the linked list is correctly able to reverse the order of items within itself. Asserts that the list
has the correct ordering of items after being reversed AND after being reversed a second time.
"""
items = range(1, 10) # test list of items ( numbers 1 - 10)
linked_list = LinkedList()
for item in items: # add each test item to linked list
linked_list.add(item)
linked_list.reverse() # reverse order of both lists
items = reversed(items)
for ll_item, item in zip(linked_list.next(), items): # check that each index holds same item
self.assertEqual(ll_item, item)
linked_list.reverse() # reverse linked list again
for ll_item, item in zip(linked_list.next(), range(1, 10)): # check that each index holds same item
self.assertEqual(ll_item, item)