笨办法学python3续 learn more python 3 in hard way ex15-2 queue in smart way

代码:

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())

在这里插入图片描述
没毛病= ----------------=
奇了怪了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值