先进先出

  • 入队
  • 出队
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
队列
Copyright ©conghaoyuan@gmail.comm
"""
class Queue:
def __init__(self) -> None:
self.queue = []

def print_queue(self):
lists = []
for i in range(len(self.queue)-1, -1, -1):
lists.append(self.queue[i])
print(lists)

def push(self, data):
self.queue.append(data)

def pop(self):
if len(self.queue) == 0:
print("stack empty")
return
return self.queue.pop(0)


if __name__ == '__main__':
queue = Queue()
queue.push(1)
queue.push(2)
queue.push(3)
queue.push(4)
queue.print_queue()

print(queue.pop())
print(queue.pop())
queue.print_queue()