Last In, First Out principle - LIFO 📚

Last In, First Out principle - LIFO 📚
Working with the stack, it's important to remember the principle that is always followed: Last In, First Out (LIFO). 

This means that the last item added to the top of the stack will be the first to leave, allowing the system to process the next request. 

The pop and push methods are essential for adding and removing items from the top of the stack.

Example:
When a user navigates a website by clicking through different pages, they can use the back button to return to the previous view. In this case:

- The current view is popped off the stack.
- The previous view is pushed back into place, restoring the earlier state.

Alternatively, the user can continue to push new views onto the stack as they explore different sections of the website, maintaining the order in which views are added and removed.

LIFO is a foundational concept not just in web navigation but in many computing systems that rely on stacks to manage processes and requests.

Published: Oct 2024

← Back to Blog