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
21
votes
13 answers

What are practical applications of Queues?

What are practical applications of Queues in Computer Science. Where do we use them and why? I heard that we use them in Video Games and Computer Simulation programs, is that true? Why? Apart from these two areas what are other practical…
Muhammad Maqsoodur Rehman
  • 33,681
  • 34
  • 84
  • 124
21
votes
3 answers

How do I copy or clone a LinkedList-implemented Queue in Java?

I have a Queue q1, that is implemented as a LinkedList, and I want to define a Queue q2, that is a separate, but identical identical instance of Queue q1. How do I do that since Queue does not implement Cloneable?
Razer
  • 7,843
  • 16
  • 55
  • 103
21
votes
2 answers

python queue get size, use qsize() or len()?

I've seen instances where qsize() and len() has been used to compute the size of the queue. What is the distinction between the two?
mingxiao
  • 1,712
  • 4
  • 21
  • 33
21
votes
2 answers

Create dynamic queues with Celery

Here's my scenario: When a user logs in to my website, I queue up a bunch of tasks for the given user (typically each task takes 100s of msecs and there are 100s of tasks per user). These tasks are queued to the default Celery Queue and I have 100s…
El Diablo
  • 303
  • 1
  • 4
  • 7
21
votes
13 answers

How check if a task is already in python Queue?

I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the…
Fluffy
  • 27,504
  • 41
  • 151
  • 234
20
votes
4 answers

C#: Triggering an Event when an object is added to a Queue

I need to be able to trigger a event whenever an object is added to a Queue. I created a new class that extends Queue: public delegate void ChangedEventHandler(object sender, EventArgs e); public class QueueWithChange :…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
20
votes
2 answers

Why does the Node.js event loop require multiple phases?

Having read through dozens of articles and documents describing the Node.js event loop, such as the one provided by Node.js themselves: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/ I simply cannot wrap my head around this: WHY…
marcs
  • 281
  • 1
  • 6
20
votes
4 answers

How to convert std::queue to std::vector

I need to make use of a queue of doubles because of the good properties it has as an ordered container. I want to pass this queue to a class constructor that accepts vectors. If I do that directly I get the following error: candidate constructor…
Anthony
  • 443
  • 1
  • 5
  • 16
20
votes
5 answers

How can I learn more about why my Laravel Queued Job failed?

The Situation I'm using Laravel Queues to process large numbers of media files, an individual job is expected to take minutes (lets just say up to an hour). I am using Supervisor to run my queue, and I am running 20 processes at a time. My…
slifty
  • 13,062
  • 13
  • 71
  • 109
20
votes
3 answers

How to avoid jobs DB table locks issue when using Laravel queues?

I'm using Laravel 5.1. The queues are used for data fetching/syncing between several systems. I use the database driver, 3 "artisan queue:work --daemon" processes are running all the time. The jobs are dispatched both by system users and scheduler…
MaGnetas
  • 4,918
  • 4
  • 32
  • 52
20
votes
4 answers

Observable Stack and Queue

I'm looking for an INotifyCollectionChanged implementation of Stack and Queue. I could roll my own but I don't want to reinvent the wheel.
Goran
  • 6,798
  • 9
  • 41
  • 57
20
votes
5 answers

Laravel Artisan CLI safely stop daemon queue workers

In order to process large numbers of jobs, I run a variable number of queue workers depending on howmuch work there is to complete. I don't want to run more workers than are necessary to complete the work that needs to be done in a time period that…
Vigs
  • 1,286
  • 3
  • 13
  • 30
20
votes
4 answers

Redis - Better way of cleaning the processing queue(reliable) while using BRPOPLPUSH

Our Current Design Env Redis 2.8.17 We have implemented our reliable queue, using the pattern similar to the one described in redis documentation, under RPOPLPUSH However, we are using BRPOPLPUSH considering its blocking nature, and LPUSH for…
aspdeepak
  • 2,640
  • 2
  • 32
  • 37
20
votes
3 answers

Python: Update value of element in heapq

If I have a heapq which contains some elements like: import heapq class Element(object): def __init__(self, name, val): self.name = name self.val = val if __name__ == "__main__": heap = [] e1 = Element('A', 1) e2 =…
Ziva
  • 3,181
  • 15
  • 48
  • 80
20
votes
3 answers

C++ std::queue::pop() calls destructor. What of pointer types?

I have a std::queue that is wrapped as a templated class to make a thread-safe queue. I have two versions of this class: one that stores value types, one that stores pointer types. For the pointer type, I'm having trouble deleting the elements of…
San Jacinto
  • 8,774
  • 5
  • 43
  • 58