Kinda cool!Ī stack/queue could also be an array rather than a linked list, but as Vaidehi points out, an array isn’t the best option because they “require a set amount of memory and space to be set aside before they are created” where memory for linked lists can be distributed. Stacks/Queues + Linked Lists = Good Thingsīoth stacks and queues are often used in conjunction with good ol’ linked lists, and it’s very good for fast computation since an item will always be added to or removed from the top or bottom of the list no matter how long the list is. I’ve also heard that described as last in, last out. Another example would be managing inventory in restaurants – when I worked at a pizza shop (which was not so long ago), when refilling the pizza topping containers, we would make sure the oldest, or first, olives were the first ones to go. If our stack of cards was now a queue, we would add a new card to the bottom of the pile. The last item added to the stack will also be the first one out, just as if you placed a card on a stack of cards, the last one you put on the stack will be the first one you remove.Ī queue, on the other hand, is first in first out, a.k.a. Their main difference is in which end that adding/removing happens: FIFO and LIFOĪ stack functions quite like a stack of cards, and follows the last in first out, or LIFO, principle. All the action in terms of adding and removing items happens at their ends, and they can be used in conjunction with other, more literal data types. Stacks and queues are quite similar in that they are both linear and abstract data structures (meaning they describe the behavior of a data structure). Stacks & Queues are similar but not the same
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |