# coding:utf8 class Queue(): def __init__(self): self.items = [] def enqueue(self, item): self.items.insert(0, item) def dequeue(self): return self.items.pop() def isEmpty(self): return len(self.items) == 0 def size(self): return len(self.items) if __name__ == "__main__": alist = [1, 2, 3, 4, 5] q1 = Queue() q2 = Queue() for i in alist: q1.enqueue(i) while q1.size() > 0: while q1.size() > 1: q2.enqueue(q1.dequeue()) print(q1.dequeue()) q1, q2 = q2, q1
#输出结果
#5
#4
#3
#2
#1