Stack (abstract data type)
In computer science, a
stack is a particular kind of abstract data type or collection in which the principal operations on the collection are the addition of an entity to the collection, known as
push and removal of an entity, known as
pop. The relation between the push and pop operations is such that the stack is a Last-In-First-Out data structure. In a LIFO data structure, the last element added to the structure must be the first one to be removed. This is equivalent to the requirement that, considered as a linear data structure, or more abstractly a sequential collection, the push and pop operations occur only at one end of the structure, referred to as the
top of the stack. Often a
peek or
top operation is also implemented, returning the value of the top element without removing it. A stack may be implemented to have a bounded capacity. If the stack is full and does not contain enough space to accept an entity to be pushed, the stack is then considered to be in an overflow state. The pop operation removes an item from the top of the stack.