0.5 Stack
Credit: PSADS 2.3.
A stack (sometimes called a “push-down stack”) is an ordered collection of items where the addition of new items and the removal of existing items always takes place at the same end. This end is commonly referred to as the “top.” The end opposite the top is known as the “base.”
- The ordering principle is called LIFO, last-in first-out.
- Stacks are fundamentally important, as they can be used to reverse the order of items.
- Example:
- Every web browser has a Back button. As you navigate from web page to web page, those pages are placed on a stack (actually it is the URLs that are going on the stack). The current page that you are viewing is on the top and the first page you looked at is at the base. If you click on the Back button, you begin to move in reverse order through the pages.