Stack – Data Structure

Ankur Kulhari

Outline:

  • Introduction
  • Implementation (static and dynamic)
  • Application

Stack – Introduction

  • Stack is a linear data structure.
  • Stack follows the order as:
    • LIFO(Last In First Out) or
    • FILO(First In Last Out).
  • Operations performed on the stack:
    • Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition.
    • Pop: Removes an item from the stack. The items are popped in the LIFO order.
      • If the stack is empty, then it is said to be an Underflow condition.
  • Peek or Top: Returns top element of stack.
  • isEmptyReturns true if stack is empty, else false.

Stack -Implementation:

  • Stack can be implemented in two ways:
    • Using array
    • Using linked list

Stack – Implementation – using Array:

  • PUSH Operation Algorithm
                begin procedure push: stack, data
                   if stack is full
                      return null
                   endif
                   top = top + 1
                   stack[top] = data
                end procedure
Stack Push Operation

Stack Push Operation

 

  • POP Operation Algorithm:
               begin procedure pop: stack 
	           if stack is empty 
		       return null 
	           endif 
	           data = stack[top] 
	           top = top - 1 
	           return data 
                end procedure
Stack POP Operation

Stack POP Operation

What do you think about the article?

This site uses Akismet to reduce spam. Learn how your comment data is processed.