#842 – The Stack Data Type

stack is a data type used to store a collection of items and which has the following properties:

  • Elements can be added to the stack 
  • Elements can be removed from the stack, but only in the reverse order from the order in which they were added

Adding an item is known as a Push operation.  Removing an item is known as a Pop operation.

You can think of a stack data type as being like a physical stack of trays.  You can add new trays, but only to the top of the pile (a Push).  You can remove a tray from the stack, but only from the top of the stack (a Pop).

Like a physical stack of trays, we refer to the location of the last item added to the stack as the top of the stack.

A stack is also known as a LIFO (Last-In, First-Out) structure.

842-001

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #842 – The Stack Data Type

  1. Pingback: Dew Drop – May 14, 2013 (#1,546) | Alvin Ashcraft's Morning Dew

  2. Just a small add-on: there’s also a Peek(), which allows to get the top item without removing it from stack.

Leave a comment