本文整理匯總了Python中LinkedList.LinkedList.popHead方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.popHead方法的具體用法?Python LinkedList.popHead怎麽用?Python LinkedList.popHead使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.popHead方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import popHead [as 別名]
class Queue:
def __init__(self):
self._ls = LinkedList()
self.size = 0
def __str__(self):
return "Queue contains:{0}".format(self._ls)
def __iter__(self):
return self
def next(self):
if not self.isEmpty():
j = self.dequeue()
return j
else:
raise StopIteration()
def enqueue(self,n):
self._ls.append(n,None)
self.size += 1
def dequeue(self):
j = self._ls.popHead()
self.size -= 1
return j.key
def isEmpty(self):
return self.size == 0
def show(self):
self._ls.show()
示例2: __init__
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import popHead [as 別名]
class Stack:
def __init__(self):
self.ls = LinkedList()
self.size = 0
def __str__(self):
print("Stack size is:", self.size)
if self.isEmpty():
return "The stack is Empty"
else:
return "Stack contains:{0}".format(self.ls)
def __iter__(self):
return self
def next(self):
if not self.isEmpty():
return self.pop()
else:
raise StopIteration()
def push(self, elm):
# the way the stack works is that the LinkedList is appended
# form the front
self.ls.addToFront(elm, None)
self.size += 1
def pop(self):
# The first element in the LL is the last element that's added
# returning the head gives the last node placed onto the stack
self.size -= 1
return self.ls.popHead().key
def isEmpty(self):
return self.size == 0
def show(self):
print(self.ls)