As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [queue]

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

Filter by
Sorted by
Tagged with
28 votes
4 answers
9k views

FIFO data structure in pure C

I programmed a generic queue in pure C and I'd love to receive some feedback from other programmers. You may use the following questions to guide your review. Is the API well thought and idiomatic? ...
Gabriel's user avatar
  • 1,053
22 votes
1 answer
25k views

Thread-safe concurrent FIFO queue in C++

Is this the correct way to implement a thread-safe concurrent FIFO queue in C++? It requires passing unsigned char* arrays of binary data. Thread Safe Concurrent ...
PerracoLabs's user avatar
19 votes
5 answers
24k views

A custom thread-pool/queue class

I wanted a class which executes any number of tasks but only a certain amount at the same time (e.g. to download various internet content and keep the overall download speed at a good level). The ...
H.B.'s user avatar
  • 335
16 votes
4 answers
2k views

String Queue implementation

Is the implementation clean enough & can be used in production? I tried to write clean & bug-free code. It looks good to me. I would appreciate any improvement suggestions. One question I ...
Pollob's user avatar
  • 163
16 votes
2 answers
727 views

Interprocess Communication in a Farmer-Worker setup

The following code is my first C program I have made for an university assignment about Interprocess Communication. This involved creating a parent process, the farmer, and then creating a certain ...
skiwi's user avatar
  • 10.6k
15 votes
3 answers
2k views

Testing a lock-free job queue

I've created a lock-free job queue and with the tests I've written, which is also very fast. That makes me doubt my benchmark procedure, so I'm hoping the collective knowledge will shed some light on ...
Arjan's user avatar
  • 321
15 votes
5 answers
17k views

Java blocking queue

...
a3user's user avatar
  • 151
14 votes
4 answers
7k views

Circular Bounded Queue using C#

As an exercise, I have implemented a circular bounded queue using arrays as the base data structure. I'd appreciate it if someone can review it for me. ...
brainydexter's user avatar
13 votes
1 answer
2k views

Implementation of std::deque (obsolete)

Warning: This implementation is obsolete, because it doesn't meet the standard. Specifically, while the standard guarantee any pointers and references to elements to remain valid after insertion or ...
Dannyu NDos's user avatar
12 votes
3 answers
12k views

STL queue implementation

I've implemented a simple C++ STL like queue. (I've tried to follow @LokiAstari stack implementation code fashion) ...
Kaidul Islam's user avatar
12 votes
5 answers
648 views

FiniteArrayQueue type with interface and unit tests

Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
Phrancis's user avatar
  • 20.3k
12 votes
4 answers
3k views

Animal shelter simulation using Queues

This is of one the interesting problems I've solved: An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (...
Mayur Kulkarni's user avatar
12 votes
3 answers
16k views

Tail implementation in C

Write the program tail, which prints the last n lines of its input. By default, n is 10, let ...
cristid9's user avatar
  • 1,271
12 votes
1 answer
487 views

Using decorated methods in a subclass of deque to dump its state to a JSON file

I am sub-classing an object in python and I need to overload a bunch of the methods with very similar logic, essentially a call to super() and then some additional operations. I want to avoid ...
Alex's user avatar
  • 223
12 votes
1 answer
15k views

Continuously receive messages async from Azure Service Bus Queues

I'd like to get input on my approach of continuously receiving messages from an Azure Service Bus queue using the async part of the library. My main concern being whether its "safe" to use Task....
sitereactor's user avatar
11 votes
3 answers
4k views

HackerRank Implement Queue using two stacks Solution

Challenge Problem Statement - Implement a Queue using two Stacks I implemented dequeue() in \$O(1)\$ at the cost of enqueue() ...
KshitijV97's user avatar
11 votes
4 answers
1k views

Type-generic queue implementation using singly linked lists

Simple lightweight queue implementation using data size registration and singly linked lists as the underlying type Update #2 ...
Mode77's user avatar
  • 619
11 votes
3 answers
17k views

Generic deque implementation

I implemented a generic Deque<T> data structure. Please, review this implementation. Deque.java: ...
kharandziuk's user avatar
11 votes
2 answers
1k views

Espresso Queue simulation

I was asked to do a technical test with the following specification, but my solution was rejected and I was not selected for the available position (Junior to "normal" level, with 4 days of time to ...
Juha Untinen's user avatar
11 votes
2 answers
21k views

First-come first-serve job scheduling algorithm

I tried to make the code for implementation of first-come first-serve job scheduling algorithm as used by operating systems. How can I make it better? I am using turbo C++ compiler ...
vidit jain's user avatar
10 votes
5 answers
1k views

Simple server to manipulate priority queues

In a few months I'll work on a C++ project that could span a year or two. I've a strong C background and for the usual reasons I always chose C over C++ (please forgive me). To extend my capabilities ...
Yorick de Wid's user avatar
10 votes
5 answers
2k views

RingQueue implementation using std::array

I've recently finished implementing a ring queue based on std::array in C++11. I tried to write the code as if I were going to submit it to the C++ Standard ...
Bizkit's user avatar
  • 1,719
10 votes
2 answers
889 views

Twitter Streaming Client - Round#2

I've been experimenting with the Twitter Streaming API and would like some critical feedback. Specifically code correctness, code smells, overall structure, and my usage of collections and queues. ...
weare138's user avatar
  • 541
10 votes
2 answers
10k views

Multi producer/consumer queue (without Boost) in C++11

Not lock-free, but still only C++11 and no Boost. It also supports timeouts. ...
GabiMe's user avatar
  • 395
10 votes
3 answers
1k views

A concurrent queue that supports exactly two threads and not more. One thread is allowed to push, the other to pop

My header file implementation: ...
Chani's user avatar
  • 273
9 votes
3 answers
12k views

Thread-safe queue

This is what I have which is mostly based on code I've found on Stack Overflow. How good is it? Can you suggest better implementation? ...
Oleg Vazhnev's user avatar
9 votes
4 answers
1k views

Implementation of a queue

It's been nearly a year I've been using C++, and I have just implemented this queue. I've tested it in many different scenarios, and it seems to work completely fine. Would you mind telling me what ...
maufcost's user avatar
  • 379
9 votes
1 answer
76k views

Queue Implementation using a Linked List

For understanding the concepts, I've implemented the Queue data structures using a linked list. Is there anything to improve? LinkList.java ...
Arun Prakash's user avatar
  • 1,483
9 votes
2 answers
2k views

Concurrent FIFO in C++11

I have implemented a simple FIFO that can optionally be used by either a single thread or way to pass data between threads. The class is templated with arguments for the types the queue will contain ...
schrödinbug's user avatar
9 votes
1 answer
3k views

A thread-safe priority queue keeping its elements unique

This class is intended to be used in situations where queue.Queue does not suffice, because the following two properties are needed. Every item in the queue can ...
Tobias Hermann's user avatar
8 votes
3 answers
1k views

Temporary queue to prevent duplication

I am making a Reddit bot and to prevent my bot from posting to the same comment twice, instead of making a database, I decided I would rather create a temporary list (or "queue") that once appended to,...
docyoda's user avatar
  • 111
8 votes
4 answers
6k views

Animal Shelter in Java

I have been working my way through the problems in the book Cracking the Coding Interview. The instructions were to maintain an animal shelter that operates on a first in, first out basis (i.e. it is ...
Average's user avatar
  • 841
8 votes
4 answers
50k views

Array Implementation of Queue

I've implemented the queue data structures using array in java. Anything I need to change in my code? Queue.java ...
Arun Prakash's user avatar
  • 1,483
8 votes
3 answers
6k views

fix ugly initialisation in while loop over queue

I have a loop structure, that I really don't like. It's the initialisation I find appalingly ugly. Is there a nicer way to do the following? ...
Martijn's user avatar
  • 585
8 votes
6 answers
1k views

Implement queue using two stacks

Although it's a well-known algorithm, I thought to implement it from the perspective of a coding interview. I want to know if I can improve my code somehow. So, given the time constraint, is this a ...
CodeYogi's user avatar
  • 5,087
8 votes
1 answer
4k views

Calculate the running median

I'm trying to solve a challenge where you need to calculate the median every time you add a number. say you have a list of numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ...
Nilzone-'s user avatar
  • 1,416
8 votes
2 answers
1k views

Singly linked list queue class

I have a Queue class that is basically a single linked list. It has 2 remove methods. What would be the cleanest way to avoid duplication of the code? Only the ...
Kimmo's user avatar
  • 183
8 votes
2 answers
49k views

Writing a thread-safe queue in C++

I created a SafeQueue class, which stores pointers. It has two methods: push: Adds a new pointer to the queue next: If the queue is empty, returns nullptr. ...
Iter Ator's user avatar
  • 271
8 votes
2 answers
608 views

Sending data to a database in size-limited chunks

I have a method which takes a parameter which is Partition enum. This method will be called by multiple background threads around same time period by passing ...
david's user avatar
  • 1,647
8 votes
1 answer
590 views

JSON messaging queue with transformation and dispatch rules

I put together this code as part of a practice problem. The instructions for the program are to accept JSON messages, transform the messages and then dispatch them to the right queue according to a ...
Cauder's user avatar
  • 183
8 votes
2 answers
3k views

Lockless Queue Multiple-Reader Singler-Writer in C++

I wrote a lockless queue for sending small objects from a single thread to a random worker thread. Assumptions: x86/x86_64 compiled with GCC one thread may Write(), multiple threads may Read() ...
Bob65536's user avatar
  • 852
8 votes
2 answers
2k views

Sequential execution

I made a class that I think satisfies the conditions: Actions can be added to the queue at any time by any number of clients. ...
Ted's user avatar
  • 83
8 votes
1 answer
4k views

Yet another multi-producer single consumer queue in C++17

Here's an implementation of a multi-producer single consumer queue that I wanted to use with tasks such as logging from multiple points in a program to a single sink. The implementation is inspired ...
Vilas Chitrakaran's user avatar
7 votes
4 answers
611 views

Double-ended queue and iterators

I have created a double-ended container, but I have doubts about its efficiency in terms of performance. Can you please criticize the code? What can be done extra, such as shortening it? ...
Rıfat Tolga Kiran's user avatar
7 votes
3 answers
187 views

Very basic Integer queue in C

I've never written a queue before and literally just took the concepts and tried to code something up. I decided to write a basic integer queue and as an example/driver I use a queue of size 5 which ...
the_endian's user avatar
  • 1,333
7 votes
2 answers
615 views

Cyclic queue using an array

I tried to implement a cyclic Queue using an array, as a task from a coding interview. Please comment about style, as well as any edge cases I may have missed. ...
Gilad's user avatar
  • 5,311
7 votes
3 answers
4k views

Fixed-size array-based implementation of a queue

For my computer science class, I've implemented a Java version of a queue and would like to know if there's anything wrong with it. After my tests, it seems to work fine, but maybe somebody can point ...
Maxbit's user avatar
  • 173
7 votes
3 answers
3k views

Lock-free SPMC queue

Here is my lock-free queue implementation for single producer with some preallocated memory. T is a simple type with no need for move operations. I don't use ...
Guinzoo's user avatar
  • 73
7 votes
2 answers
1k views

MailQueue implementation with auto start - stop

Previous question was a little portion of the mailQueue. I finished the MailQueue, which has the ability to start and stop ...
chillworld's user avatar
  • 3,872
7 votes
1 answer
937 views

BFS for creating a queue without repetitions and with loops in the graph

I have a pipeline with loops of filters and one input filter. The rest are splitters, transform and output. I would like my code to go over the filters and push them into a queue (order is important)...
Gilad's user avatar
  • 5,311

1
2 3 4 5
9