A stack is a LIFO (Last In First Out) arrangement of data. The simplest example would be the process/thread stack. Although such an implementation is rather array based, it fairly illustrates the mechanism.
However, most of the time, we would not know the size of the required stack in advance, maybe just a rough estimation. Not to mention the fact that we would hardly need to store only double or quad words; we'll mostly have more complex structures. The most common implementation of a stack would be a singly linked list addressed by a top pointer only. Ideally, only three operations are permitted on a stack:
- push: This is used to add a new member to the list
- top: This is used to view/read the last added member of the list
- pop: This is used to remove the last added member from the list
While the push and pop operations are equivalent to adding and removing a member from/to a singly linked list, the TOP operation basically means getting the value of the top pointer and so obtaining access to the topmost (added last) member of the list.