Posted By

Implementation of Stack in C Push Pop Display

Education 48

#include<stdio.h>


int s[5]; 


int top=-1; 


void push()


     {


         int value;


         if (top==5-1){


             printf("Stack is Full");


         }


         else


         {


             printf("\nEnter value to push  ");


             scanf("%d",&value);


             top=top+1;


             s[top]=value;


         }


     }


void pop()


     {


         int value;


         if(top==-1){


             printf("\nStack is Empty\n");


         }


         else


         {


             printf("\nDelete your last element was %d ", s[top]);


             top=top-1;


         }


     }


void disp()


     {


         int i;


         if(top==-1){


             printf("\nStack is Empty\n");


         }


         else


         {


             printf("\nStact Elemets is ");


             for(i=top;i>=0;i--)


             printf("%d  ",s[i]);


         }


     }


int main()


 {


     int ch;


     while(1){


         printf("\n###### Menu ######\n");


         printf("1. PUSH\n2. POP\n3. DISPLAY\n4. EXIT \n\n");


         printf("Enter Your Choice:  ");


         scanf("%d",&ch);


         if(ch==1)


             push();


         else if(ch==2)


             pop();


         else if(ch==3)


             disp();


         else if(ch==4)


             break;


         else


             printf("Invalid Choice");


     }


     return 0; 


}    

Implementation of Stack in C Push Pop Display

Login to comment login

Latest Jobs
  • Bangladesh Inland Water Transport Authority Junior River Surveyor Job Circular
    Bangladesh Inland Water Transport Authority
    Education: Bachelor Degree
    Experience: 0 Years
    Deadline: 10 Feb 2019
  • Bangladesh Inland Water Transport Authority River Surveyor Job Circular
    Bangladesh Inland Water Transport Authority
    Education: Bachelor Degree
    Experience: 0 Years
    Deadline: 10 Feb 2019
  • Bangladesh Navy Sub Assistant Engineer Job Circular
    Bangladesh Navy
    Education: B.Sc in Mechanical/ Computer Science Engineering
    Experience: 0 Years
    Deadline: 9 Feb 2019
  • LankaBangla Finance Limited Trainee Credit Analyst Job Circular
    LankaBangla Finance Limited
    Education: Graduate/Post Graduate
    Experience: 0 Years
    Deadline: 2 Feb 2019
  • Jahangirnagar University Store Keeper Job Circular
    Jahangirnagar University
    Education: Bachelor Degree
    Experience: 0 Years
    Deadline: 7 Feb 2019