Stack: Data Structure algorithm

Stack is a data structure which has ordered list of similar data type. Stack is a Last In First Out (LIFO) structure. In simple words, stack is a like a bag; whatever you put at last comes out first. Now, lets understand the algorithm for stack.

  • start
  • Display push or pop
  • Read input
  • If push
    • Read input data
    • Check for Stack overflow
    • If flase
      • push data into stack
      • Increment stack top pointer
    • If true 
      • Display “Stack overflow”
      • Stop
  • If pop
    • Check for Stack underflow
    • If false
      • Read stack top data
      • Display stack top data
      • Decrement  stack top pointer
    • if true
      • Display stack underflow
      • Stop
  • Stop
Lets understand this with an example of stack using simple array which stores integer type data.

Hope you understood stack algorithm and program, Try your own using algorithm. We can  implement stack using dynamic memory allocation also. I will explain you about that when we discuss Linked lists. You can download this program by below link.

Leave your comments in comments section, feel free to ask your doubts.
Next post will be of applications of stack.

Sujay K