Hot answers tagged

31 votes
Accepted

String Queue implementation

using System; If you're going to say using System then don't be putting lots of System.s ...
Eric Lippert's user avatar
  • 14.9k
25 votes
Accepted

HackerRank Implement Queue using two stacks Solution

Algorithmic complexity for combined operations Containers are interesting elements in most programming languages: they have an internal state, namely their elements and therefore their size. This ...
Zeta's user avatar
  • 19.2k
24 votes
Accepted

FIFO data structure in pure C

None of your QUEUE_* functions validate their input arguments before using them. NULL pointers will be a problem, particularly ...
bta's user avatar
  • 819
14 votes

String Queue implementation

Bug? The queue destroys itself during a resize because ...
t3chb0t's user avatar
  • 44.2k
14 votes
Accepted

Thread-safe message queue

Create a class that implements the thread-safe queue Your program has two queues, and already you see a lot of code duplication. It would be great to create a class ...
G. Sliepen's user avatar
  • 54.1k
13 votes
Accepted

FiniteArrayQueue type with interface and unit tests

On testing... Your tests are incomplete, certainly. Your test on isEmpty only tests two conditions: a newly instantiated queue which has never had anything added ...
nhgrif's user avatar
  • 25.3k
13 votes

FIFO data structure in pure C

This looks really nice! Here we go: Is the API well thought and idiomatic? Mostly. For a library as simplistic as this, you probably want to avoid creating a special enum when returning ...
hsdfhsdal's user avatar
  • 131
13 votes
Accepted

Temporary queue to prevent duplication

collections.deque Why not use a collections.deque with a max_len? ...
RootTwo's user avatar
  • 9,955
12 votes
Accepted

Animal Shelter in Java

The model has failed I would expect from an animal shelter to actually store animals. (Well, in programming terms, a representation of animals.) Your implementation is not an animal shelter, it's an ...
janos's user avatar
  • 111k
12 votes
Accepted

A thread-safe priority queue keeping its elements unique

Let's start with the good: Ohh recent Python 3, nice! Good documentation Good use of typing. This is great for datastructures. Good formatting of your code. Nice ...
Bailey Parker's user avatar
11 votes
Accepted

Animal shelter simulation using Queues

Structure So your structure is definitely a bit off. First of all, you made your Node generic, which is good, as it could theoretically work with any content - ...
tim's user avatar
  • 25.1k
11 votes
Accepted

High Performance Blocking Queue C#

This question has a number of misconceptions You are unlikely to develop a real-time system using .NET because of unbounded GC times ConcurrentQueue<T> ...
vvotan's user avatar
  • 787
11 votes
Accepted

Type-generic queue implementation using singly linked lists

Yes, you don't check the malloc return value. Along the same line, you should not cast it. is_empty implementation is anti-idiomatic. It should be ...
vnp's user avatar
  • 56.3k
10 votes

FiniteArrayQueue type with interface and unit tests

First, a minor nitpick. ...
nhgrif's user avatar
  • 25.3k
10 votes

FIFO data structure in pure C

When you have queued a pointer you can never get that pointer again. It is also very difficult to know when that pointer has been dequeued. This is a recipe for leaks. Instead returning the pointer ...
ratchet freak's user avatar
10 votes
Accepted

Redefining queue with different front and rear

Your teacher is right. This is not a good FIFO. Is there any problem in my code ? We're not ready to go there, yet. Let's first worry about problems with the design. We want to implement a queue ...
J_H's user avatar
  • 22.1k
9 votes
Accepted

Writing a thread-safe queue in C++

I see some things that may help you improve your code. List all required #includes The code needs the following #includes to ...
Edward's user avatar
  • 66.4k
9 votes
Accepted

Concurrent FIFO in C++11

I'm in a bit of a hurry so I'll only touch on the big high level stuff that I noticed. Abuse of SFINAE I think that the way you are designing two different use cases into one template class and ...
Emily L.'s user avatar
  • 16.6k
9 votes
Accepted

Cyclic queue using an array

Yay exceptions! Though it isn't reservered for execution-ending errors, I would avoid throwing an OutOfMemoryException, because usually it signals something very ...
VisualMelon's user avatar
  • 7,431
9 votes

HackerRank Implement Queue using two stacks Solution

You might want to look at the discussion tab for why the code is timing out. Basically the code should reverse the input stack only when peek() or ...
pacmaninbw's user avatar
  • 23.8k
9 votes

Type-generic queue implementation using singly linked lists

Don't cast the result value of malloc(). (In general, using casts in C is a yellow card. Using C-style casts in C++ is a red card) The reason to cast the result of <...
frozenca's user avatar
  • 1,693
8 votes

Animal shelter simulation using Queues

I was working on refactoring your code. When I was finished I saw that @tim already posted an answer. He address the most what I also wanted to point out, but in mine opinion he forget 1 thing. <...
chillworld's user avatar
  • 3,872
8 votes
Accepted

Double-ended queue and iterators

I really recommend using an explicit type for your linked-list node: ...
coderodde's user avatar
  • 27.6k
8 votes
Accepted

Fixed-size array-based implementation of a queue

API The method names you chose are unusual for queues. It's good to get inspiration from the JDK. Following the example of Queue, I suggest these renames: ...
janos's user avatar
  • 111k
8 votes
Accepted

(Optionally Concurrent) FIFO

Your popped elements will not be destructed. You move them but that isn't the same as being destructed and it doesn't guarantee that memory will be released. Furthermore your container requires T to ...
Emily L.'s user avatar
  • 16.6k
8 votes
Accepted

Implementation of a queue

I see a number of things that may help you improve your code. Use the required #includes The code uses std::exception, ...
Edward's user avatar
  • 66.4k
8 votes
Accepted

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

I don't think that what you're doing is good style. I think you're adding a lot of extra complexity and places for things to go wrong, or become hard to understand, or whatever. I don't think you lose ...
Dan Oberlam's user avatar
  • 7,784
7 votes

FiniteArrayQueue type with interface and unit tests

You should be using generics. Forcing the caller to cast dequeued results from Object isn't really acceptable. The ...
200_success's user avatar
7 votes
Accepted

Sending data to a database in size-limited chunks

I waited a few days to get other answers to your questions. now I feel I can add my 2 cents. First off, the obvious: This is one single method. It does: Polling a queue Serialising a message into a ...
MrBrushy's user avatar
  • 1,198
7 votes
Accepted

JavaScript Queue

Like Thomas Junk said, your wrapper pretty much maps 1:1 to JavaScript's existing, native Array. The biggest difference is that your ...
Flambino's user avatar
  • 33k

Only top scored, non community-wiki answers of a minimum length are eligible