A queue hands items out in the order they arrived: the first-in, first-out rule, how it differs from a stack and why it is fair. Cut from the lesson "Queues" in the CS50 Shorts courses. Source: CS50 Shorts, "Queues" by CS50, Harvard University Original: https://cs50.harvard.edu/x/2024/shorts/queues/ Licence: CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/) Changes: Cut to about a minute, reformatted to vertical with a blurred background and re-encoded; captions, summary and thumbnail generated by Upgram. Not endorsed by CS50 or Harvard University. Shared under the same licence.
We're going to talk now about queues. So a queue, similar to a stack, is another kind of data structure that we can use to maintain data in an organized way. Similar to a stack, it can be implemented as an array or a linked list. Unlike a stack, the rules that we use to determine when things get added and removed from a queue are a little bit different. Unlike a stack, which is a LIFO structure, last in, first out, a queue is a FIFO structure, F-I-F-O, first in, first out. Now, queues, you probably have an analogy to queues if you've ever been in line at an amusement park or at a bank. There's sort of a fairness implementing structure, right? The first person in line at the bank is the first person who gets to speak to the teller. It would be sort of a race to the bottom if the only way you got to speak to the teller at the bank was to be the last person in line. Everybody would always want to be the last person in line. And the person who was there first, who has been waiting for a while, could be there for hours and hours and hours before they have a chance to actually withdraw any money at the bank. And so queues are sort of the fairness implementing structure. But that doesn't necessarily mean that stacks are a bad thing, just that queues are another way to do it. So again, a queue is first in, first out, versus a stack which is last in, first out.
Чтобы продолжить, установите приложение
Ставьте «Нравится», комментируйте, подписывайтесь на авторов и следите за прогрессом в приложении Upgram.
Скачать Upgram
Комментарии