Python零基础学习笔记(三十七)—— 栈和队列



#模拟栈结构
stack = []
#压栈(向栈里面存数据)
stack.append("A")
print(stack)
stack.append("B")
stack.append("C")
print(stack)
#出栈(在栈里面取数据)
res1 = stack.pop()
print(res1)
print(stack)
res2 = stack.pop()
print(res2)
print(stack)
res3 = stack.pop()
print(res3)
print(stack)


#模拟队列
import  collections
#创建队列
queue = collections.deque()
print(queue)
#进队
queue.append("A")
print(queue)
queue.append("B")
print(queue)
#出队
res1 = queue.popleft()
print(res1)
print(queue)
res2 = queue.popleft()
print(res2)
print(queue)

上一篇:java8 Stream Pipelines 浅析


下一篇:Kronos宣布收购软件公司Empower Software