扩展 双端队列

 1 class  DoubleQueue(object):
 2     '''实现双端队列'''
 3     def __init__(self):
 4         self.__lst = []
 5         # 创建一个容器容纳队列成员
 6 
 7     def append_frontdata(self,data):
 8         '''在头部添加元素'''
 9         self.__lst.insert(0,data)
10 
11     def append_reardata(self,data):
12         '''在尾部添加元素'''
13         self.__lst.append(data)
14 
15     def pop_headdata(self):
16         # 从头部删除数据
17         return self.__lst.pop(0)
18 
19     def pop_reardata(self):
20         # 在尾部删除数据
21         return self.__lst.pop()
22 
23     def is_empty(self):
24         return self.__lst == []
25         # 判断是否为空
26     
27     def size(self):
28         # 返回队列长度
29         return len(self.__lst)

2020-04-15

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12707455.html