zoukankan      html  css  js  c++  java
  • 栈 队列 和 双向队列

    # 栈
    # 特点: 先进后出
    # class StackFullException(Exception):
    #     pass
    #
    # class StackEmptyException(Exception):
    #     pass
    #
    # class Stack:
    #
    #     def __init__(self, size):
    #         self.size = size
    #         self.lst = [] # 存放数据的列表
    #         self.top = 0 # 栈顶指针
    #
    #     # 入栈
    #     def push(self, el):
    #         if self.top >= self.size:
    #             raise StackFullException("your stack is full!!!!!")
    #         self.lst.insert(self.top, el) # 放元素
    #         self.top += 1 # 栈顶指针向上移动一下
    #
    #     # 出栈
    #     def pop(self):
    #         if self.top == 0:
    #             raise StackEmptyException("your stack is empty!!!!!")
    #         self.top-=1
    #         el = self.lst[self.top]
    #         return el
    #
    # s = Stack(6)
    # s.push("宝宝")
    # s.push("我还")
    # s.push("记得")
    # s.push("你")
    # s.push("刚刚")
    # s.push("说的话")
    # print(s.pop())
    # print(s.pop())
    # print(s.pop())
    # print(s.pop())
    # print(s.pop())
    # print(s.pop())
    # import queue
    # q = queue.Queue()
    # q.put("李嘉诚1")
    # q.put("李嘉诚2")
    # q.put("李嘉诚3")
    # q.put("李嘉诚4")
    # q.put("李嘉诚5")
    #
    # print(q.get())
    # print(q.get())
    # print(q.get())
    # print(q.get())
    # print(q.get())
    
    
    # from collections import deque
    #
    # d = deque() # 创建双向队列
    # d.append("宝宝") #  在右侧添加
    # d.append("no")
    # d.append("way")
    # d.append("哈哈")
    # d.appendleft("娃哈哈") # 在左边添加
    # d.appendleft("爽歪歪")
    # d.appendleft("优酸乳")
    #
    #
    # print(d.pop()) # 从右边拿数据
    # print(d.pop()) # 从右边拿数据
    # print(d.pop()) # 从右边拿数据
    # print(d.pop()) # 从右边拿数据
    # print(d.popleft()) # 从左边拿数据
    # print(d.popleft()) # 从左边拿数据
    # print(d.popleft()) # 从左边拿数据
    #
    #
    

      

  • 相关阅读:
    MySQL的字符编码体系(一)——数据存储编码
    poj 1659 Frogs' Neighborhood 度序列可图化 贪心
    POJ 1083 && HDU 1050 Moving Tables (贪心)
    cocos2d-x wp8 中文显示问题
    Linux多线程编程
    how tomcat works 五 servlet容器 上
    SecureCRT 选择Courier New等其他字体.
    如何设置secureCRT的鼠标右键为弹出文本操作菜单功能
    SecureCRT中文显示乱码
    ZooKeepr日志清理
  • 原文地址:https://www.cnblogs.com/work14/p/10187655.html
Copyright © 2011-2022 走看看