#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.



About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: