Questions tagged [queue]

A queue is an ordered, first-in-first-out data structure. Typical implementations of queues support pushing elements to the back and popping them off the front position.

  • A queue is not limited to a fixed capacity
    • A bounded queue is a queue limited to a fixed number of items
  • A doubly linked list is a good implementation choice

Operations

  • enqueue - pushes an element to the end of the queue
  • dequeue - pops an element from the front of the queue

See Also

Resources

Queue Wikipedia Article

11098 questions
31
votes
2 answers

Dumping a multiprocessing.Queue into a list

I wish to dump a multiprocessing.Queue into a list. For that task I've written the following function: import Queue def dump_queue(queue): """ Empties all pending items in a queue and returns them in a list. """ result = [] #…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
30
votes
12 answers

c# Adding a Remove(int index) method to the .NET Queue class

I would like to use the generic queue class as described in the .NET framework (3.5) but I will need a Remove(int index) method to remove items from the queue. Can I achieve this functionality with an extension method? Anyone care to point me in the…
Alex
  • 3,099
  • 6
  • 41
  • 56
30
votes
3 answers

Where should you use BlockingQueue Implementations instead of Simple Queue Implementations?

I think I shall reframe my question from Where should you use BlockingQueue Implementations instead of Simple Queue Implementations ? to What are the advantages/disadvantages of BlockingQueue over Queue implementations taking into consideration…
Vaibhav Kamble
  • 3,579
  • 5
  • 23
  • 16
30
votes
7 answers

Pre-allocate space for C++ STL queue

I'm writing a radix sort algorithm using queues and I would like to have a STL queue allocate space before I start adding things to the queue so that I can avoid constant dynamic resizing operations. Even though this doesn't exist, I want something…
Brandon Pelfrey
  • 2,449
  • 6
  • 22
  • 22
29
votes
1 answer

Difference between 's emplace and push

What are the differences between 's emplace and push? here's explanation about the std::queue::emplace and std::queue::push . Both methods add element after its current last element, return None.
Dami.h
  • 321
  • 1
  • 3
  • 7
29
votes
1 answer

How to obtain the results from a pool of threads in python?

I have searched here about how to do threading in python, but by far i haven't been able to get the answer i need. I'm not very familiar with the Queue and Threading python classes and for that reason some of the answers present here makes no sense…
Rafael Rios
  • 564
  • 1
  • 7
  • 20
29
votes
5 answers

When would I use a priority queue?

The only example of using the priority queue I know of, is the Dijkstra's Algorithm (for calculating minimum cost) In what other situations would it be useful?
Oleksiy
  • 37,477
  • 22
  • 74
  • 122
29
votes
6 answers

Convert a Queue to List

What is the fastest way to convert a Queue into a List while keeping the Queue order?
MBZ
  • 26,084
  • 47
  • 114
  • 191
29
votes
4 answers

Python: Queue.Empty Exception Handling

After a short debate with someone about exception handling in Python - sparked by the handling of a queue object - I thought I'd throw it out there... METHOD 1: import Queue q = Queue.Queue() try: task=q.get(False) #Opt 1: Handle task here…
user1014903
  • 293
  • 1
  • 3
  • 5
28
votes
3 answers

How to implement Priority Queues in Python?

Sorry for such a silly question but Python docs are confusing... Link 1: Queue Implementation http://docs.python.org/library/queue.html It says that Queue has a class for the priority queue. But I could not find how to implement it. class…
codersofthedark
  • 9,183
  • 8
  • 45
  • 70
28
votes
3 answers

Persistent Work Queue in C#

Imagine I want to have a small network of worker drones possibly on separate threads and possibly on separate processes or even on different PCs. The work items are created by a central program. I'm looking for an existing product or service that…
101010
  • 14,866
  • 30
  • 95
  • 172
28
votes
6 answers

Thread and Queue

I am interested in knowing what would be the best way to implement a thread based queue. For example: I have 10 actions which I want to execute with only 4 threads. I would like to create a queue with all the 10 actions placed linearly and start the…
Pillard
  • 281
  • 1
  • 3
  • 3
28
votes
4 answers

Laravel 5.4 - php artisan cache:clear does not clear cache files when using 'file' cache driver

Laravel 5.4 app. CACHE_DRIVER is set to file and QUEUE_DRIVER is set to sync in .env. When I run php artisan cache:clear It says Cache cleared successfully yet I still have 236K of files in my storage/framework/cache directory. Frustrated by this, I…
fronzee
  • 1,668
  • 2
  • 21
  • 32
28
votes
2 answers

Queue vs JoinableQueue in Python

In Python while using multiprocessing module there are 2 kinds of queues: Queue JoinableQueue. What is the difference between them? Queue from multiprocessing import Queue q = Queue() q.put(item) # Put an item on the queue item = q.get() # Get an…
axcelenator
  • 1,497
  • 3
  • 18
  • 42
28
votes
3 answers

Why are Stack and Queue implemented with an array?

I'm reading C# 4.0 in a Nutshell by the Albahari brothers and I came across this: Stacks are implemented internally with an array that's resized as required, as with Queue and List. (pg 288, paragraph 4) I can't help but wonder why. LinkedList…
Matt
  • 589
  • 6
  • 10