Discussing the article: "From Basic to Intermediate: Queues, Lists, and Trees (II)"

 

Check out the new article: From Basic to Intermediate: Queues, Lists, and Trees (II).

This is an article that you, dear reader, should study carefully. That is due to the nature of the material presented here. Although we have tried to present the material as simply and informatively as possible, the information provided here can certainly seem quite complex to those who are just beginning to learn programming. Nevertheless, this is no reason to lose heart or ignore what is explained here, as this article will establish a link between two completely different, though closely related, topics.

Well, it is quite likely that if you're just starting out in programming, you're still a bit confused about where and how to apply what we covered in the previous article. Nevertheless, in many situations, the ability to apply what was discussed and explained there can play a decisive role in your career as a programmer. But you have probably noticed that both the FIFO queue and the circular queue have one thing in common: the elements in them are always processed in the order in which they were added to the queue. In other words, the oldest element is always read first, and therefore the newest element in the queue is always read last. However, we often need to reverse this order. So, we want the newest element to be read first, and the oldest element in the queue to be read last.

One might even think that, to do this, it would be enough simply to change the order in which elements placed in a FIFO queue or a circular queue are read. In fact, in some practical situations, that is exactly what happens. However, there is a type of queue designed specifically to make this possible without having to modify existing code. This type of queue, designed specifically for reversing queue order, is called a stack.

A stack is nothing more than what its name implies. In other words, when we add new elements, we cannot remove older elements without first removing the most recent ones. There is even a toy that perfectly illustrates what a stack is and where it can be used. This toy is shown in the following image.

For those who aren't familiar with this toy, it is known as the Tower of Hanoi. Believe me, this toy has already been used in the past to analyze and compare processors. This is because there are ways to use it to obtain an accurate estimate of processing speed. However, because many processors began to be optimized to speed up the algorithm itself rather than the CPU's actual computation speed, this comparison model was ultimately abandoned. If you'd like to try solving the Tower of Hanoi in practice, you can check out the Somatemática website.


Author: CODE X