

If the stack is full and does not contain enough slots to accept new entities, it is said to be an overflow – hence the phrase “stack overflow”. isEmpty – return whether the stack contains no more items.Ī stack can also be implemented to have a maximum capacity.top – look at the item on the top of the stack without removing it.pop – remove the last item added to the top of the stack.push – add an item to the top of the stack.The basic operations which define a stack are: In abstract terms, a stack is a linear list of items in which all additions to (a “push”) and deletions from (a “pop”) the list are restricted to one end – defined as the “top” (of the stack). Candy, chip, and cigarette vending machines operate on the same principle the last item loaded in the rack is dispensed first. This property is commonly referred to as last in first out, or LIFO. In computer science parlance, a stack is a sequential collection with a particular property, in that, the last object placed on the stack, will be the first object removed.

In common usage, a stack is a pile of objects which are typically arranged in layers – for example, a stack of books on your desk, or a stack of trays in the school cafeteria. In this article I’ll introduce you to two basic abstract data types – stack and queue – which have their origins in everyday usage. Most of us are familiar with stacks and queues in normal everyday usage, but what do supermarket queues and vending machines have to do with data structures? Let’s find out.

It creates a wall between what can be done to the underlying data and how it is to be done. A data structure, or abstract data type (ADT), is a model that is defined by a collection of operations that can be performed on itself and is limited by the constraints on the effects of those operations.
