本文整理匯總了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()
示例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..."