A Stack is an Abstract Data Type (ADT) to store and retrieve values in a "Last-In, First-Out"(LIFO) fashion.

Stacks are used when we need to access data in reverse order of their arrival. They are commonly used in recursive function calls, expression parsing, depth first search in graphs etc.

Stack Operations Edit

The following operations can be performed on a stack:

  • push() - add an item to the top of the stack
  • pop() - remove an item from the top of the stack
  • peek() - look up the value of topmost item of the stack without removing it
  • isEmpty() - checks if the stack is empty
  • isFull() - checks if the stack is full