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
84
votes
11 answers

Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations

I came across this question: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations. I initially thought of using a min-heap data structure which has O(1) complexity for a get_min(). But push_rear() and…
bits
  • 8,110
  • 8
  • 46
  • 55
83
votes
4 answers

How do I store javascript functions in a queue for them to be executed eventually

I have created a Queue class in javascript and I would like to store functions as data in a queue. That way I can build up requests (function calls) and respond to them when I need to (actually executing the function). Is there any way to store a…
Matt
80
votes
10 answers

A Queue that ensure uniqueness of the elements?

I'm looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique. (all further insertion will have no effect) It's that possible, or will I…
Antoine Claval
  • 4,923
  • 7
  • 40
  • 68
76
votes
3 answers

Clear all items from the queue

How can I clear a queue. For example I have datas in a queue, but for some reason I don't need the existing data, and just want to clear the queue. Is there any way? Will this work: oldQueue = Queue.Queue()
Mokus
  • 10,174
  • 18
  • 80
  • 122
74
votes
4 answers

Laravel queue process timeout error

I'm on Laravel using php artisan queue:listen to run queued jobs. One of these jobs is fairly involved and takes a long time, and so I'm getting the following error: [Symfony\Component\Process\Exception\ProcessTimedOutException] …
Will Durney
  • 1,168
  • 2
  • 13
  • 16
69
votes
2 answers

Python multiprocessing.Queue vs multiprocessing.manager().Queue()

I have a simple task like that: def worker(queue): while True: try: _ = queue.get_nowait() except Queue.Empty: break if __name__ == '__main__': manager = multiprocessing.Manager() # queue =…
novicef
  • 803
  • 1
  • 8
  • 9
68
votes
10 answers

Sequencing ajax requests

I find I sometimes need to iterate some collection and make an ajax call for each element. I want each call to return before moving to the next element so that I don't blast the server with requests - which often leads to other issues. And I don't…
Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
68
votes
8 answers

Producer/Consumer threads using a Queue

I'd like to create some sort of Producer/Consumer threading app. But I'm not sure what the best way to implement a queue between the two. So I've some up with two ideas (both of which could be entirely wrong). I would like to know which would be…
Gareth
  • 2,180
  • 5
  • 19
  • 24
67
votes
2 answers

Array-Based vs List-Based Stacks and Queues

I'm trying to compare the growth rates (both run-time and space) for stack and queue operations when implemented as both arrays and as linked lists. So far I've only been able to find average case run-times for queue pop()s, but nothing that…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
66
votes
13 answers

A generic priority queue for Python

I need to use a priority queue in my Python code, and: am looking for any fast implementations for priority queues optimally, I'd like the queue to be generic (i.e. work well for any object with a specified comparison operator). Looking around for…
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
64
votes
3 answers

Is there a performance difference between pooling connections or channels in rabbitmq?

I'm a newbie with Rabbitmq(and programming) so sorry in advance if this is obvious. I am creating a pool to share between threads that are working on a queue but I'm not sure if I should use connections or channels in the pool. I know I need…
Lostsoul
  • 25,013
  • 48
  • 144
  • 239
62
votes
5 answers

In C# would it be better to use Queue.Synchronized or lock() for thread safety?

I have a Queue object that I need to ensure is thread-safe. Would it be better to use a lock object like this: lock(myLockObject) { //do stuff with the queue } Or is it recommended to use Queue.Synchronized like…
Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168
62
votes
8 answers

Limit size of Queue in .NET?

I have a Queue object that I have initialised to a capacity of 2, but obviously that is just the capacity and it keeps expanding as I add items. Is there already an object that automatically dequeues an item when the limit is reached, or is the…
tags2k
  • 82,117
  • 31
  • 79
  • 106
62
votes
3 answers

What is the symbol for a queue?

In a flowchart or process diagram, what is the symbol for a FIFO queue?
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
60
votes
12 answers

Queue ajax requests using jQuery.queue()

I am using jQuery.queue() for the first time and haven't quite grasped it. Could someone please point out what I'm doing wrong? Looking in firebug I am still seeing my POST requests firing at the same time - so I'm wondering if I'm calling…
MBax
  • 1,139
  • 2
  • 10
  • 7