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


Python LinkedList.size方法代碼示例

本文整理匯總了Python中LinkedList.LinkedList.size方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.size方法的具體用法?Python LinkedList.size怎麽用?Python LinkedList.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在LinkedList.LinkedList的用法示例。


在下文中一共展示了LinkedList.size方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_size

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
def test_size(): 
	l_list = LinkedList()
	assert l_list.size() == 0
	l_list.insert("Batman")
	l_list.insert("Superman")
	assert l_list.size() == 2
	l_list.delete("Superman")
	assert l_list.size() == 1
開發者ID:prathamtandon,項目名稱:python-algorithms-and-data-structures,代碼行數:10,代碼來源:LinkedList_test.py

示例2: RemoveDuplicatesTest

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
class RemoveDuplicatesTest(unittest.TestCase):

    def setUp(self):
        self.default_list = LinkedList()
        self.default_list.insert('a')
        self.default_list.insert('b')
        self.default_list.insert('c')
        self.default_list.insert('c')
        self.default_list.insert('d')
        self.default_list.insert('d')

    def test_remove_duplicates(self):
        remove_duplicates(self.default_list)
        self.assertEqual(self.default_list.size(), 4)
開發者ID:ZachLiuGIS,項目名稱:Algorithm-Enthusiasts,代碼行數:16,代碼來源:test.py

示例3: LinkedListTest

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
class LinkedListTest(unittest.TestCase):

    def setUp(self):
        self.default_list = LinkedList()
        self.default_list.insert('a')
        self.default_list.insert('b')
        self.default_list.insert('c')
        self.default_list.insert('d')

    def test_insert(self):
        self.default_list.insert('z')
        self.assertEqual(self.default_list.head.get_data(), 'z')
        self.assertEqual(self.default_list.head.get_next().get_data(), 'd')

    def test_get_next(self):
        self.assertEqual(self.default_list.head.get_next().get_data(), 'c')

    def test_search(self):
        # search head
        self.assertEqual(self.default_list.search('d'), self.default_list.head)
        # normal search
        self.assertEqual(self.default_list.search('c'), self.default_list.head.get_next())
        # search value not in list
        self.assertEqual(self.default_list.search('e'), None)

    def test_delete_head(self):
        self.default_list.delete('d')
        self.assertEqual(self.default_list.head.get_data(), 'c')
        self.assertEqual(self.default_list.size(), 3)

    def test_delete_tail(self):
        self.default_list.delete('a')
        self.assertEqual(self.default_list.size(), 3)

    def test_delete_not_exist(self):
        self.assertEqual(self.default_list.delete('e'), None)
開發者ID:ZachLiuGIS,項目名稱:Algorithm-Enthusiasts,代碼行數:38,代碼來源:test_LinkedList.py

示例4: range

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
list1.insert(8)
list1.insert(2)

#add elements in second linked list. Below I'm inserting number 813
list2.insert(3)
list2.insert(1)
list2.insert(8)

print "== Initial list1 =="
list1.printlist()

print "== Initial list2 =="
list2.printlist()

#compare total elements in lists and accordingly add zeros to make them of same size
if list1.size() > list2.size():
    diff = list1.size() - list2.size()
    for i in range(0, diff):
        list2.insert(0)
elif list1.size() < list2.size():
    diff = list2.size() - list1.size()
    for i in range(0, diff):
        list1.insert(0)

print "After making same size..."
print "== list1 =="
list1.printlist()

print "== list2 =="
list2.printlist()
開發者ID:rohitswarke,項目名稱:LinkedListAddition,代碼行數:32,代碼來源:add_linkedlists.py

示例5: testLargeSize

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
 def testLargeSize(self):
   ll = LinkedList()
   for i in range(0, 10000):
     ll.addNode(randint(1, 10))
   self.assertEqual(ll.size(), 10000)
開發者ID:nitsnwits,項目名稱:ds,代碼行數:7,代碼來源:testLinkedList.py

示例6: testSize

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
 def testSize(self):
   ll = LinkedList()
   ll.addNode(1)
   self.assertEqual(ll.size(), 1)
開發者ID:nitsnwits,項目名稱:ds,代碼行數:6,代碼來源:testLinkedList.py


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