If you need to forward , Please indicate the source : Xiaoting's python https://www.cnblogs.com/xxtalhr/p/10293817.html

Welcome to xiaotinger's blog :

If you have any questions, please leave a message under the blog or add the author's wechat :tinghai87605025  or QQ :87605025

python QQ Communication group :py_data 483766429

Blog Garden :http://www.cnblogs.com/xxtalhr/


One 、 Concept

queue (queue) It's a first in, first out (First In First Out) The linear table , abbreviation FIFO. Queues allow insertion at one end , And delete at the other end . The end of the line is allowed to be inserted , Allow to delete the end for the team head . Queues are not allowed to operate in the middle

Two 、 effect

decoupling : Make the program loose coupling directly , Modify a function , There won't be a tandem .

Improve processing efficiency :FIFO = Now in, first out ,LIFO = After the first out .

notes : Queues can send multiple threads concurrently , Processing of arranged threads , And every thread that needs to be processed only needs to put the requested data into the memory of the queue container , Threads don't need to wait , When the data has been processed , The thread can fetch the data on time . The thread requesting data only has a relationship with this queue container , Threads that process data down Dropping does not affect the thread requesting data , The queue will be sent to other threads to process the data , It's decoupled , Increase of efficiency . There will be a sequential container in the queue , The list is different from this container , Although the data in the list is arranged , But the data will be kept after it is taken away , The data of this container in the queue will not be retained after being fetched . When it is necessary to exchange information safely between multiple threads , Queues are especially useful in thread programming .

 class Queue:
def queue(self):
''' The team '''
def dequeue(self):
''' Out of the team '''
if __name__ == '__main__':
xxt = [1, 2, 3, 4]
# It's equivalent to inserting elements at the end of the team
xxt.insert(1, 10)
xxt.insert(0, 20)#0 At the end of the team
print('insert:',xxt) # It's equivalent to deleting elements from the head of the team
''' result

insert: [20, 1, 10, 2, 3, 4]

pop: [20, 1, 10, 2, 3]


3、 ... and 、 Introduction to queue parameters

Queue.Queue(maxsize=0)   FIFO, If maxsize Less than 1 That means the queue length is infinite

Queue.LifoQueue(maxsize=0)   LIFO, If maxsize Less than 1 That means the queue length is infinite

Queue.qsize()   Returns the size of the queue

Queue.empty()   If the queue is empty , return True, conversely False

Queue.full()   If the queue is full , return True, conversely False

Queue.get([block[, timeout]])   Read the queue , Take out the data , No data will wait timeout Waiting time

Queue.put(item, [block[, timeout]])   Write a queue , Put in the data ,timeout Waiting time

Queue.queue.clear()   Clear queue

class queue.PriorityQueue(maxsize=0) Priority queues can be set when storing data , The lower the number of priority settings, the higher the level

Queue.get(timeout = 1) If 1 Seconds later, I quit without getting the data

Queue.get_nowait() Take the data , If there's no data queue.Empty abnormal

Queue.task_done() Subsequent calls tell the queue , The processing of the task is complete .

 from collections import deque
queue = deque(["Eric", "John", "Michael"])
print('queue.popleft:',queue) ''' result
queue: deque(['Eric', 'John', 'Michael'])
queue.append: deque(['Eric', 'John', 'Michael', 'Terry'])
queue.append: deque(['Eric', 'John', 'Michael', 'Terry', 'Graham'])
queue.popleft: deque(['John', 'Michael', 'Terry', 'Graham'])
queue.popleft: deque(['Michael', 'Terry', 'Graham'])

source : https://www.cnblogs.com/xiangsikai/p/8185031.html

OCP Training instructions link :https://mp.weixin.qq.com/s/2cymJ4xiBPtTaHu16HkiuA

OCM Training instructions link :https://mp.weixin.qq.com/s/7-R6Cz8RcJKduVv6YlAxJA

Xiaoting's python Growing up , There are still many shortcomings , With the deepening of study and work , Will be the past blog content gradually improve and perfect .

Do more important things ......

python data structure queue (queue) More articles about

  1. Python One way queue Queue Module details

    Python One way queue Queue Module details One way queue Queue, fifo '''A multi-producer, multi-consumer queue.''' try: import thread ...

  2. Python The queue of Queue

    Let's get to know today python Queues (Queue) queue is especiall useful in threaded programming when information must be ...

  3. Python data structure ——— queue

    queue (Queue) A queue is also a collection of sequential elements , New elements are added at one end of the queue , be called “ A party ”(rear), The removal of an existing element occurs at the other end of the queue , be called “ Team leader ”(front), Unlike stacks , The queue can only be inserted at the end of the queue ...

  4. python Message queue Queue

    example 1: Message queue Queue, Do not name the file "queue.py", Otherwise, an exception will be reported "ImportError: cannot import name 'Queue'" ...

  5. Python The queue of queue Module USES Common problems and usage

    python in , Queues are the most common form of data exchange between threads .queue A module is a module that provides queue operations , Easy to use though , But if you're not careful , There will still be some accidents . 1. Blocking mode import queue q = queu ...

  6. use go Implementation of commonly used algorithms and data structures —— queue (queue)

    queue brief introduction Queues are a very common data structure , We can often see it in our daily life . A typical queue is shown below ( The picture is from segmentfault): It can be seen that queuing is basically the same as queuing in our daily life . All follow FIFO(F ...

  7. data structure -- queue Queue

    One . Introduction to queue Definition queue (queue) In computer science , It's a first in, first out linear table . It only allows deletion at the front of the table , And insert at the back end of the table . The end of the insertion operation is called the tail of the queue , The end of the delete operation is called the queue head . There's no... In the queue ...

  8. python Implementation queue (queue)

    A queue is a first in, first out data structure , The main operations include joining the team , Out of the team . Join the elements of the team to the end , Take the elements out of the team from the team leader . Here's a simple list simulation of queues , It is realized as follows : queue()is_empty()size()enqueue ...

  9. [C++][ data structure ] queue (queue) The implementation of the

    For the definition of queue , I'm ready for the predecessors . The implementation of queue is very similar to stack . I added something directly to the code of the stack I implemented , Globally replaced some identifiers , This queue is implemented . What I have achieved is a queue<value> Containers ...

Random recommendation

  1. Mysql Complete manual ( Note 2 , Usage data and performance optimization )

    One . Using data 1. Using variables MySQL We can also store it in user-defined variables select Result of query , So that in the future select Use in query . They only exist during the customer session , But they provide a convenient and efficient way to join queries ...

  2. android Bitmap Class method properties Detailed instructions

    ( turn :http://blog.csdn.net/ymangu666/article/details/37729109) 1.  BitMap class public void recycle()—— Reclaiming bitmaps takes up ...

  3. JSP Use

    JSP course : http://www.w3cschool.cc/jsp/jsp-tutorial.html jsp grammar : Every language has its own grammar ,JAVA There is ,JSP Though it is JAVA On the application of , But according to ...

  4. The most complete in history JavaScript Work notes

    /* * JavaScript Look at object functions */ function resultTest( obj ){ var resultTest = ''; $.each(obj,function(key,va ...

  5. arcgis api for flex remove esri map Control logo sign

    In the process of applicationComplete Method private function reallyHideESRILogo(map : Map) : void { for(var i : ...

  6. Html skeleton 、 Basic grammar

    Ten thousand Zhang tall buildings rise from the ground , Don't be greedy , Feet on the ground , To look up at the stars One .HTML skeleton Standard skeleton <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitio ...

  7. 【 The first part 】07Leetcode Brush problem

    Two . Look for the minimum value in the rotation sort array subject :153. Find Minimum in Rotated Sorted Array C++ Soution 1: class Solution { public: ...

  8. Vue.js Use -http request

    Vue.js Use -ajax Use 1. Why use ajax The previous example , Using local simulation data , adopt ajax Request server data . 2. Use jquery Of ajax Library example new Vue({ el: '#app' ...

  9. Database fault diagnosis (Troubleshooting) One of the serious database failure cases caused by the performance problem of

    I haven't been here for a long time to write , There's a little time today , Come here and write something about what happened recently . Some time ago , A telecom service user has been rebooted due to several recent downtime of a core production library , After the intervention of various personnel failed , Sent me an email , Now the problem has caused serious consequences , ...

  10. Oracle PLSQL Demo - 19. The Conduit function[ Query the whole table list Pipe return ]

    create or replace function function_demo RETURN emp PIPELINED as Type ref_cur_emp IS REF CURSOR RETU ...