當前位置: 首頁>>代碼示例>>Python>>正文


Python LinkedList.reverse方法代碼示例

本文整理匯總了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
開發者ID:WillYee,項目名稱:LinkedListDemo,代碼行數:14,代碼來源:LinkedListTest.py

示例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 ]')
開發者ID:nitsnwits,項目名稱:ds,代碼行數:10,代碼來源:testLinkedList.py

示例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)
開發者ID:Clarksj4,項目名稱:Algorithms_and_Data_Structures,代碼行數:20,代碼來源:test.py


注:本文中的LinkedList.LinkedList.reverse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。