/    /  Data Structures-Stack Data Structure

Stack Data Structure

 

Stack is a linear data structure that follows a particular order in which the operations are performed. The orders can be LIFO or FILO.

It performs the following operations:

  1. Push
  2. Pop
  3. Peek or Top
  4. isEmpty

 

Time complexities in stack operations:

We cannot run loops in Push, Pop, Peek, or Top, and isEmpty, as they all take O(1) time.

 

Applications of the stack:

  1. It does prefix/infix conversions.
  2. It provides redo/undo functions.
  3. It balances the symbols.
  4. It is widely used in various algorithms, such as the histogram program.
  5. It is used as primary management for a running purpose in modern-day computers.
  6. It does string reversal.
  7. It does backtracking.
  8. It is used in graph algorithms.

 

Implementing stack by using linked list:

 

 

ReferenceStack Data Structure