• python 队列


    栈:后进先出

    单向队列:先进先出
    双向队列:
    import collections
    d = collections.deque()
    d.append('1')
    print(d)
    class:
        append: Add an element to the right side of the deque.
      appendleft: Add an element to the left side of the deque. 
      clear: Remove all elements from the deque. 
      
    def count(self, value): # real signature unknown; restored from __doc__
    """ D.count(value) -> integer -- return number of occurrences of value """
    return 0

    def extend(self, *args, **kwargs): # real signature unknown
    """ Extend the right side of the deque with elements from the iterable """
    pass

    def extendleft(self, *args, **kwargs): # real signature unknown
    """ Extend the left side of the deque with elements from the iterable """ #先进后出
        eg:
           >>>d.extendleft(['1', 'dd', 'cc'])
           deque(['cc', 'dd', '1', '3', '1', '2', 'll', 'aa', 'ss'])
    pass

    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
    """
    D.index(value, [start, [stop]]) -> integer -- return first index of value.
    Raises ValueError if the value is not present. 返回队列元素的索引值,从0开始。
    """
    return 0

    def insert(self, index, p_object): # real signature unknown; restored from __doc__
    """ D.insert(index, object) -- insert object before index """
    pass

    def pop(self, *args, **kwargs): # real signature unknown
    """ Remove and return the rightmost element. """
    pass

    def popleft(self, *args, **kwargs): # real signature unknown
    """ Remove and return the leftmost element. """
    pass

    def remove(self, value): # real signature unknown; restored from __doc__
    """ D.remove(value) -- remove first occurrence of value. """ 可以是元素可以是索引,从右至左删除遇到的第一个元素,先进先出
    pass

    def reverse(self): # real signature unknown; restored from __doc__
    """ D.reverse() -- reverse *IN PLACE* """ 翻转
    pass

    def rotate(self, *args, **kwargs): # real signature unknown
    """ Rotate the deque n steps to the right (default n=1). If n is negative, rotates left. """将队列右端的n个值移动到左端
    pass
     
    单向队列
    def qsize(self):
            """Return the approximate size of the queue (not reliable!)."""
            self.mutex.acquire()
            n = self._qsize()
            self.mutex.release()
            return n
    
        def empty(self):
            """Return True if the queue is empty, False otherwise (not reliable!)."""
            self.mutex.acquire()
            n = not self._qsize()
            self.mutex.release()
            return n
    
        def full(self):
            """Return True if the queue is full, False otherwise (not reliable!)."""
            self.mutex.acquire()
            n = 0 < self.maxsize == self._qsize()
            self.mutex.release()
            return n
         def put(self, item, block=True, timeout=None):
              """Put an item into the queue.
         def get(self, block=True, timeout=None):
            """Remove and return an item from the queue.
     
    import queue
    d = queue.Queue()
    d.put('123')
    d.put('456')
    print(d.qsize())
    p = d.get()
    print(d) # Queue中的数据无法直接输出,这样的结果是打印的内存中的地址,可以用get按先进先出的顺序拿。
    print(p)
  • 相关阅读:
    Servlet监听器及在线用户
    数据分页jdbc+mysql实现
    使用ajax验证用户名重复
    Mysql中的事务
    用户登录注册案例分析
    Java连接mysql数据库
    Java连接sqlite数据库
    虚拟主机TOMCAT配置
    用jquery控制表格奇偶行及活动行颜色
    JDK安装后 没有tools.jar 和dt.jar包的解决办法
  • 原文地址:https://www.cnblogs.com/ernest-zhang/p/5558470.html
Copyright © 2020-2023  润新知