手写栈和队列
1、栈(特点:后进先出)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # 栈:后进先出 2 class Stack(object): 3 4 def __init__(self): 5 self.data = [] 6 7 def push(self, item): 8 return self.data.append(item) 9 10 def pop(self): 11 return self.data.pop()
2、队列(特点:先进先出)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # 队列:先进先出 2 class Queue(object): 3 4 def __init__(self): 5 self.data = [] 6 7 def push(self, item): 8 self.data.insert(0, item) 9 10 def pop(self): 11 return self.data.pop()