class Queue(object):
def __init__(self):
self.list = []
def push(self, item):
self.list.append(item)
def pop(self):
return self.list.pop()
def is_empty(self):
return self.list == []
def size(self):
return len(self.list)
def __str__(self):
return "人物(%r)" % self.list
s = Queue()
print("入队前为空:", s.is_empty())
s.push("蓝湛")
s.push("魏婴")
s.push("谢怜")
s.push("花城")
s.push("小明")
print('入队之后的长度:', s.size())
print(s.pop())
print('出队之后的长度:', s.size())
print("入队后为空:", s.is_empty())
print(s)
python设计一个队列的表示和实现的演示程序,其基本操作有初始化队列、判队列空否入队列、出队列等功能。
![](https://img-home.csdnimg.cn/images/20240711042549.png)