Stack

Written by

Sonal Moga

Stacks

Stacks are a type of Data Structure that allows the addition and deletion of an element only at one end, the front end. Stacks are also called Abstract Data Types mainly because there are only two operations possible on a Stack, i.e., Push & Pop.

Elements are sequentially organized in a stack where the last element inserted is the first one to be removed; hence it follows the LIFO (Last-In-First-Out) principle.

To understand better, we can refer stack in data structure with a stack of plates in a basket. The last plate put in the stack will be the first one to be removed from it. The addition is called Push and deletion is called Pop.

 

Basic operations that can be performed on a Stack

  • PUSH refers to add an element in the stack. If the stack is full, it is an Overflow Condition.
  • POP is removing an item from the stack; it is always the topmost entity in a stack.
  • PEEK returns the top element of the stack without removing it.
  • isEmpty returns TRUE if the stack is empty or else it returns FALSE.
  • isFull returns TRUE if stack is full or else it returns FALSE.

Application of Stacks

  • The simplest application of stack is reversal of Words or Strings.
  • In browsers, every time we visit a page on the internet, it gets added to the stack of the list and when we hit the back button, the page we were viewing currently is removed first.

 

Stack