Stacks & Queues

Stacks and queues are both really useful ways of organizing data. Although these data structures are built-in to many modern languages, it is still essential to understand how they work so that we can be good programmers and use them effectively!

Stacks are First In Last Out (FILO), meaning the last thing you PUSH onto the stack is the first thing that comes out after a POP. Think about stacking dinner plates from the dishwasher, then getting one when it’s time for dinner. You’ll probably just get the one from the top, which is the last one you placed onto the pile.

Queues are First In First Out (FIFO), meaning the first thing you ENQUEUE is the first thing that comes out when you DEQUEUE. Think about a line at the grocery store. You arrive and go to the end of the line. As more people are served, they leave the line from the front in the order they entered.

Here’s a useful video related to Stacks/Queues and Java

Leave a Reply

Your email address will not be published. Required fields are marked *