利用两个栈实现队列
1 class Queue: 2 def __init__(self): 3 self.stack1 = [] 4 self.stack2 = [] 5 6 def push(self, node): 7 self.stack1.append(node) 8 9 def pop(self): 10 if not self.stack2: 11 while self.stack1: 12 self.stack2.append(self.stack1.pop()) 13 return self.stack2.pop() 14 return self.stack2.pop()