Tuesday, 19 September 2017

Introduction to Stacks with some interesting application with its Implementing Code in C language and Video lecture link

Below are some most important features of Stacks are mentioned and please go through all these points for better understanding:
  • The stack is a linear data structure.
  • A stack is a recursive data structure.
  • Stacks are dynamic data structures.
  • Stacks follow Last In First Out (LIFO) principle.
  • The stack can either be a fixed size one or it may have a sense of dynamic resizing.
  • LIFO means that the data element which is inserted last into the stack is the first which is to be deleted.
  • The stack is a structure where insertion and deletion of data element should take place at one end known as the top of the stack.
  • There are basically six operations that can be performed on stacks are push(), pop(), display(), peek(), isFull() and isEmpty().
  • Stacks should be implemented with Linear Array (LA) and Linked List data structure.
  • In the stack, push() function is implemented when you want to insert new data element into it.
  • In the stack, the pop() function is implemented when you want to delete a data element from it.
  • In the stack, display() function is implemented when you want to display all data element from the stack.
  • In the stack, peek() get the top data element of the stack, without removing it.
  • In the stack, isFull() is used to check if the stack is full.
  • In the stack, isEmpty() is used to check if the stack is empty.
  • In the stack, TOP is a variable which used to store the position of the top data element of the stack, all the operation of the stack starting from the TOP variable.



Application of Stack:

  • It is used to reverse a word.
  • It is used for Infix to Postfix /Prefix conversion
  • It is used for Forwarding and backward feature in web browsers
  • It support for recursion in an algorithm
  • It is used for compiler's syntax check for matching braces is implemented by using the stack.
  • It is used in programs like Knight tour problem, rat in a maze, N queen problem and sudoku solver
  •  It is used in Redo-undo features at many places like editors, Photoshop 

Implementation of Stack using Linear Array:

 #include<stdio.h>
#define SIZE 10
// All stack function deceleration
void push(int);
void pop();
void display();
int stack[SIZE],top=-1;
// Definition of the push() functions with all possible insertion conditions
void push(int value)
{
    if(top==SIZE-1)
    printf("\n Stack is full!!!!insertion is not possible");
    else
    {
        top++;
        stack[top]=value;
        printf("\n Insertion success!!!");
    }
}
// Definition of the pop() functions with all possible deletion conditions
void pop()
{
    if(top==-1)
        printf("\n Stack is empty!deletion is not possible");
     else
        {
            printf("\n Deleted:%d",stack[top]);
            top--;
        }
}


// Definition of the display() functions with all possible conditions
void display()
{
    if(top == -1)
        printf("\n Stack is empty!!!");
        else
        {
            int i;
            printf("\n Stack elements are:\n");
            for(i=top;i>=0;i--)
            {
                printf("%d\n",stack[i]);
            }
        }
}
// Implementation of main() where all the function call of push(), pop() and display() are used
int main()
{
    int i;
    for(i=1;i<=5;i++)
    {
        push(i);
    }
    display();
    pop();
    pop();
    display();
}
To watch the implementation of this program please go to the below link:




Thanks 
Mukesh Rajput
 

No comments:

Post a Comment

Thanks
Mukesh Rajput