Using an Array to represent a Circular Queue

preview_player
Показать описание
Using an Array to represent a Circular Queue. Complete module here:
Рекомендации по теме
Комментарии
Автор

That moving animation was extremely helpful in showing the difference between the physical first element (at index 0 in C/C++) and logical first element!

ab
Автор

You legend, I was struggling with queues and pesudocode. But now I am getting better at it

yondabigman
Автор

Thank you, that got me to understand what I was missing. I was searching around trying to figure out how to advance the pointers past the last element, hence making a CIRCLE. Strangely enough, this vital piece of the puzzle was missing everywhere I looked. You actually explained it, the MODULO. I did see the MODULO in several places but nobody ever explained it. To be fair, I was looking mostly in Geeks for Geeks. It makes me wonder if those guys actually understand what they implement, or are just essentially copying and pasting code.

janssenkuhn
Автор

kudos for the best explanation on the internet.

AbuSayed-qehr
Автор

one of the best demonstration ever. Thank you sir for your contributions

hikmettas
Автор

Great job, you explained far better than my university professor.

danemorgan
Автор

Awesome, will implement this today in C++, just that when I add I must check if that location is still in-use. I have a circular array of received packets to be consumed by a slow consumer, while a fast producer will add to the queue. So concurrently producing and consuming can happen, using 2 threads. They will be blocked only on queue full or empty conditions, not by the fact consumer is slow. Thanks.

antonfernando
Автор

The easiest explanaition so far, excellent work, thx!!!

celsiusfahrenheit
Автор

Awesome explanation .. outstanding ....

Ikebena
Автор

Thank you so much, your explanation is really clear and easy to understand!

bbma
Автор

When queue is cleared, both head and tail are at -1.
Now if you AddToQ(x), tail = (-1+1)%max_size = 0, and head is still at -1.
If you execute DeleteFromQ now, it tries to return value from Queue[head] = Queue[-1]. that should not be the case.
Am I missing something here?

sayedim
Автор

Absolutely extraordinary explanation! Thank you!

HarithAldabbagh
Автор

thank you so really needed this! youre so good at explaining

brianac
Автор

Thank you for the nice explanations! Which language is the example written in?

west-gaming-space
Автор

omg, that was fantastic explanation, thank you very much Mr Gordon

govindsankarmr
Автор

Thank you for the very clear explanation. Perfect :)

RexGalilae
Автор

Thank you. It is a really good explanation.

googleuser
Автор

can the tail override the head? what happens if the queue is full and you add another element to the tail. does it override the head and the head's index is incremented by 1?

crazypigs
Автор

That was extremely helpful. Thank you.

pitchthewoo
Автор

Thank you Damian. I have one question though. You say that if head equals to tail then queue is empty. `bool isEmpty() { return head == tail}; But also you say that head points to the first element enqueued and tail points to the last element enqueued, right? So what happens if only one element is enqueued? Both head and tail show on that single element and are equal to each-other, but the container is NOT empty. How you handle this?

naghekyan