栈#模拟栈结构#栈有先后顺序的。后进的先取出,先进的最后取出stack=[] #压栈(向栈里存数据)stack.append("a")print(stack)stack.append("b")print(stack) #出栈(在栈里取数据)res1=stack.pop()print("res1=",res1)print(stack)res2 =stack.pop()print("res2=",res2)print(stack)
队列import collections #创建一个队列queue=collections.deque()print(queue) #进队queue.append("A")print(queue)queue.append("B")print(queue)queue.append("C")print(queue)#出队(取数据)#队的输出顺序先进先出res1=queue.popleft()print("res1=",res1)res2=queue.popleft()print("res2=",res2)res3=queue.popleft()print("res3=",res3)
原文地址:https://www.cnblogs.com/zlong123/p/10436372.html
时间: 2024-11-09 09:39:54