URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       Class Discussion
  HTML https://srm.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: Data Structure
       *****************************************************
       #Post#: 12--------------------------------------------------
       Stack Program using C (Data Structure)
   DIR By: prannyll
       Date: May 2, 2019, 8:31 am
       ---------------------------------------------------------
       #include<stdio.h>
       #include<conio.h>
       #include<stdlib.h>
       #define MAX 5
       void view(); void push(); void pop();
       int stack[MAX], TOP = -1;
       
       void main()
       {
       int ch;
       printf("\n ---------------------------");
       printf("\n MAIN MENU");
       printf("\n 1.View");
       printf("\n 2.Push");
       printf("\n 3.Pop");
       printf("\n Press 0 to Exit. \n >>");
       scanf("%d", &ch);
       
       switch(ch)
       {
       case 0 : exit(0);
       break;
       case 1 : view();
       break;
       case 2 : push();
       break;
       case 3 : pop();
       break;
       default : printf("\n WRONG CHOICE!");
       }
       main();
       }
       
       void view()
       {
       int i;
       if(TOP == -1)
       printf("\n STACK UNDERFLOW! \n");
       else
       {
       printf("\n STACK: \n");
       for(i = TOP; i >= 0; i--)
       printf(" %d \n", stack[i]);
       }
       }
       void push()
       {
       if(TOP >= MAX)
       printf("\n STACK OVERFLOW!");
       else
       {
       printf("\n Enter Number to Push: ");
       scanf(" %d", &stack[++TOP]);
       printf(" ELEMENT PUSHED : %d \n", stack[TOP]);
       }
       }
       
       
       void pop()
       {
       if(TOP <= -1)
       printf("\n STACK IS EMPTY!");
       else
       {
       printf("\n ELEMENT POPPED : %d", stack[TOP]);
       stack[TOP--] = NULL;
       }
       }
       *****************************************************
       Page 1 of 1