代码:
from DoubleLinkedListNode import *
from dllist import *
class Queue(object):
def __init__(self):
self.list = DoubleLinkedList()
def shift(self, obj):
"""Shifts a new element onto the back of the queue."""
self.list.shift(obj)
def unshift(self):
"""Removes the element that is first in the queue."""
self.list.unshift()
def dump(self,mark="=----="):
self.list.dump()
基本上这队列和双重链表是一样的 出队列是先进先出
调用unshift方法
这里有个问题是我把刚刚的那个自动测试搞过来 unshift() 的assert就一直报错
然后我尝试把自动化测试双向链表 = -= 没有问题
反正就很奇怪
最后我直接把测试写在同一个文件里
from DoubleLinkedListNode import *
from dllist import *
class Queue(object):
def __init__(self):
self.list = DoubleLinkedList()
def shift(self, obj):
"""Shifts a new element onto the back of the queue."""
self.list.shift(obj)
def unshift(self):
"""Removes the element that is first in the queue."""
self.list.unshift()
def dump(self,mark="=----="):
self.list.dump()
colors = DoubleLinkedList()
colors.shift("Viridian")
colors.shift("Sap Green")
colors.shift("Van Dyke")
print(colors.dump("all"))
print( colors.unshift())
print( colors.unshift())
print( colors.unshift())
print( colors.unshift())
没毛病= ----------------=
奇了怪了