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


Python LinkedList.printlist方法代碼示例

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


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

示例1: RemoveDuplicates_withbuffer

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printlist [as 別名]
from LinkedList import LinkedList

def RemoveDuplicates_withbuffer(l):
    table=[]
    node=l.head
    while node!=None:
        if node.get_data() in table:
            prev_node.set_next(node.get_next())
            node=node.get_next()
        else:
            table.append(node.get_data())
            prev_node=node
            node=node.get_next()

l= LinkedList()
l.insert(2)
l.insert(2)
l.insert(4)
l.insert(5)
l.insert(6)
l.insert(5)
l.insert(2)
RemoveDuplicates_withbuffer(l)
l.printlist()
開發者ID:gannyvenkat,項目名稱:CCI_Python,代碼行數:26,代碼來源:2_1(a)LL_Duplicates_withbuffer.py

示例2: LinkedList

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printlist [as 別名]
#lets create two linked list objects
list1 = LinkedList()
list2 = LinkedList()

#add elements in first linked list. Please make sure you are inserting unit place first followed by 10th place and then 100th place. Below I'm inserting number 287
list1.insert(7)
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..."
開發者ID:rohitswarke,項目名稱:LinkedListAddition,代碼行數:33,代碼來源:add_linkedlists.py


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