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
59
votes
7 answers

Difference between "enqueue" and "dequeue"

Can somebody please explain the main differences? I don't have a clear knowledge about these functions in programming for any language.
Omar
  • 601
  • 1
  • 5
  • 4
59
votes
4 answers

Queue vs List

I'm currently using a List as a queue (use lst[0] then lst.removeAt(0)) to hold objects. There's about 20 items max at a given time. I realized there was an actual Queue class. I'm wondering if there's any benefit (performance, memory,…
Jack
  • 5,680
  • 10
  • 49
  • 74
58
votes
7 answers

Can I get an item from a PriorityQueue without removing it yet?

I want to get the next item in queue but I don't want to dequeue it. Is it possible in Python's queue.PriorityQueue? From the docs, I don't see how can it be done
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
58
votes
15 answers

Stack and Queue, Why?

Why and when should I use stack or queue data structures instead of arrays/lists? Can you please show an example for a state thats it'll be better if you'll use stack or queue?
Alon Gubkin
  • 56,458
  • 54
  • 195
  • 288
57
votes
2 answers

Converting a deque object into list

Currently, I fetch "list" data from my storage, "deque" it to work with that data. After processing the fetched data, I have to put them back into the storage. This won't be a problem as long as I am not forced to use Python's standard "list" object…
Julius F
  • 3,434
  • 4
  • 29
  • 44
57
votes
2 answers

Queue vs Dequeue in java

What is the difference between them? I know that A queue is designed to have elements inserted at the end of the queue, and elements removed from the beginning of the queue. Where as Dequeue represents a queue where you can insert and remove…
user6503581
55
votes
10 answers

awaitable Task based queue

I'm wondering if there exists an implementation/wrapper for ConcurrentQueue, similar to BlockingCollection where taking from the collection does not block, but is instead asynchronous and will cause an async await until an item is placed in the…
spender
  • 117,338
  • 33
  • 229
  • 351
55
votes
9 answers

Using a database table as a queue

I want to use a database table as a queue. I want to insert in it and take elements from it in the inserted order (FIFO). My main consideration is performance because I have thousands of these transactions each second. So I want to use a SQL query…
Shayan
  • 2,758
  • 7
  • 36
  • 55
53
votes
4 answers

Python - What is queue.task_done() used for?

I wrote a script that has multiple threads (created with threading.Thread) fetching URLs from a Queue using queue.get_nowait(), and then processing the HTML. I am new to multi-threaded programming, and am having trouble understanding the purpose of…
J. Taylor
  • 4,567
  • 3
  • 35
  • 55
51
votes
6 answers

How to create a delayed queue in RabbitMQ?

What is the easiest way to create a delay (or parking) queue with Python, Pika and RabbitMQ? I have seen an similar questions, but none for Python. I find this an useful idea when designing applications, as it allows us to throttle messages that…
eandersson
  • 25,781
  • 8
  • 89
  • 110
49
votes
2 answers

Difference between Laravel queued event listeners vs jobs

I'm trying to wrap my head around Laravel's queued event listener vs jobs. To me, it seems like that both are very similar: Both implement the ShouldQueue interface (in the case of event listener, this is an option) Both implement the handle()…
LC Yoong
  • 1,772
  • 3
  • 15
  • 19
48
votes
16 answers

How can I remember which data structures are used by DFS and BFS?

I always mix up whether I use a stack or a queue for DFS or BFS. Can someone please provide some intuition about how to remember which algorithm uses which data structure?
captcadaver
  • 1,093
  • 2
  • 9
  • 7
46
votes
4 answers

How to iterate Queue.Queue items in Python?

Does anyone know a pythonic way of iterating over the elements of a Queue.Queue without removing them from the Queue. I have a producer/consumer-type program where items to be processed are passed by using a Queue.Queue, and I want to be able to…
pgilmon
  • 848
  • 1
  • 7
  • 10
45
votes
2 answers

SQL Server Process Queue Race Condition

I have an order queue that is accessed by multiple order processors through a stored procedure. Each processor passes in a unique ID which is used to lock the next 20 orders for its own use. The stored procedure then returns these records to the…
William Edmondson
  • 3,619
  • 3
  • 32
  • 41
44
votes
8 answers

How can I check if a Queue is empty?

In C#, how can I check if a Queue is empty? I want to iterate through the Queue's elements, and I need to know when to stop. How can I accomplish this?
MoShe
  • 6,197
  • 17
  • 51
  • 77