Author: Brandon Pearman

The views expressed here are mine alone and do not reflect the view of my employer.

  • Is a Linear data structure
  • Operations can only be performed at the end of the structure and not in the middle.

Stack Terms

  • Push: Add an item to the top of the stack.
  • Pop: Take in item off the top of the stack.
  • Peek: Look at the item at the top of the stack without changing anything.
  • Overflow: A stack is in an overflow state when attempting to push onto a full stack
  • Underflow: A stack is in an underflow state when attempting to pop off an empty stack.

A stack data structure works the same as a stack of plates, in the sense that if you put a plate on top of the stack then it will be the first one which is taken off the stack.

The last item put in the stack is the first item taken out.

For example:

  • stack.Push("A");
  • stack.Push("B");
  • stack.Push("C");
  • stack.Push("D");

After the above Pushes the stack will look like this:

When you Pop the stack, first item off the top of the stack will be "D".

  • var val = stack.Pop(); // val = "D"

Check out these links for more info:

My Stack Code