The name “stack” for this type of structure comes from the analogy to a set of physical items stacked on top of each other, which makes it easy to take an item off the top of ellis horowitz fundamentals of data structures pdf stack, while getting to an item deeper in the stack may require taking off multiple other items first. A stack may be implemented to have a bounded capacity. The pop operation removes an item from the top of the stack. Stacks are often described by analogy to a spring-loaded stack of plates in a cafeteria.
Clean plates are placed on top of the stack, pushing down any already there. When a plate is removed from the stack, the one below it pops up to become the new top. In many implementations, a stack has more operations than “push” and “pop”. Since this can be done with a “pop” and a “push” with the same data, it is not essential. An underflow condition can occur in the “stack top” operation if the stack is empty, the same as “pop”. Also, implementations often have a function which just returns whether the stack is empty. What identifies the data structure as a stack in either case is not the implementation but the interface: the user is only allowed to pop or push items onto the array or linked list, with few other helper operations.
A common use of stacks at the architecture level is as a means of allocating and accessing memory. This stack grows downward from its origin. A typical stack is an area of computer memory with a fixed origin and a variable size. Initially the size of the stack is zero. There are many variations on the basic principle of stack operations.