A stack only lets you remove the most recently added item: the last-in, first-out rule, and the two ways to build one. Cut from the lesson "Stacks" in Memory and data structures in C (CS50 Shorts). Source: CS50 Shorts, "Stacks" by CS50, Harvard University Original: https://cs50.harvard.edu/x/2024/shorts/stacks/ Licence: CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/) Changes: Cut to one 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.
But what is a stack? So it's pretty much just a special kind of structure that maintains data in an organized way. And there's two very common ways to implement stacks using two data structures that we're already familiar with, arrays and linked lists. What makes a stack special is the way in which we put information into the stack and the way we remove information from the stack. In particular, with stacks, the rule is only the most recently added element can be removed. So think about it as if it's a stack. We're sort of piling information on top of itself. And only the thing at the top of the pile can be removed. We can't remove the thing underneath because everything else would collapse and fall over. So we really are building a stack that we then have to remove piece by piece. Because of this, we commonly refer to a stack as a LIFO structure, last in, first out, L-I-F-O.
Чтобы продолжить, установите приложение
Ставьте «Нравится», комментируйте, подписывайтесь на авторов и следите за прогрессом в приложении Upgram.
Скачать Upgram
Комментарии