本文整理匯總了Python中LinkedList.LinkedList.printLL方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.printLL方法的具體用法?Python LinkedList.printLL怎麽用?Python LinkedList.printLL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.printLL方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Queue
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printLL [as 別名]
class Queue(LinkedList):
'Queue implemented as a Linked List - FIFO'
# ctor
def __init__(self):
self.queue = LinkedList()
# enqueue element into back of queue
def enqueue(self, val):
self.queue.insertBack(val)
# dequeue element from front of queue
def dequeue(self):
deqVal = self.queue.head.data
self.queue.removeFront()
return deqVal
# print out the queue
def printQueue(self):
self.queue.printLL()
示例2: Stack
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printLL [as 別名]
class Stack(LinkedList):
'Stack implemented as a Linked List - LIFO'
# ctor
def __init__(self):
self.stack = LinkedList()
# push element to top of stack
def push(self, val):
self.stack.insertFront(val)
# pop element from top of stack
def pop(self):
popVal = self.stack.head.data
self.stack.removeFront()
return popVal
# show the top element in stack
def peek(self):
print self.stack.head.data
# print out the stack
def printStack(self):
self.stack.printLL()
示例3: printMiddle
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printLL [as 別名]
from LinkedList import LinkedList
def printMiddle(head):
slow=head
fast=head
print slow.Next
while fast!=None and fast.Next!=None and fast.Next.Next!=None:
fast=fast.Next.Next
slow=slow.Next
return slow.data
if __name__=="__main__":
l=LinkedList()
l.insert(1)
l.insert(2)
l.insert(3)
l.insert(4)
l.insert(5)
l.insert(6)
l.printLL()
print printMiddle(l.head)