Stack


☞ It is a linear/sequence structure in which insertion and deletion can take place only at one end, i.e. stack’s top.

☞ It is a dynamic data structure.

☞ It is based on the principle :- LIFO (Last In First Out)

☞ We will implement stack using list.

  • PUSH operation:- To add an element to the top of stack, we use append().
  • POP operation:- To remove the element from the top of stack, we use pop().

Application of stack :

  1. Reversing a word/line.
  2. Compiler uses stacks to store the previous state of a program when a function is called or during recursion.
  3. Backtracing:- It is a form of recursion but it involves choosing only one option out of the possibilities. eg:- it is used in sudoku.
  4. Undo mechanism in Text Editors.