You are on page 1of 4

#include<stdio.h> #include<ctype.h> #include<conio.

h>

# define MAXSIZE 100 /* FUNCTION DECLARATION */ void push(int); void pop(); void display(); void create(); /* GLOBAL FUNCTION DECLARATION */ int top; int st[100]; void main() { int ch=1,i,n,num; clrscr(); printf("\n enter no of elements to craete stack"); scanf("%d",&n); if(n < MAXSIZE) { create(n); } else {

printf("\n elemnts can be upto %d",MAXSIZE); } while(ch==1){ printf("\n MAIN MENU\n"); printf("\nPress 1 to add elment(push)"); printf("\nPress 2 to delete elment(pop)"); scanf("%d",&ch); switch(ch){ case 1: printf("\n enter data.."); scanf("%d",&num); push(num); break; case 2: pop(); break; default: printf("\n invalid choice"); } printf("press 1 to continue, else press any key to escape"); scanf("%d",&ch); } getch(); } /* CREATE FUNCTION STARTS HERE */

void create(int n){ int k; for(k=0;k<n;k++){ scanf("%d",&st[k]); }top=k-1; } /* CREATE FUNCTION ENDS HERE */ /*PUSH FUNCTION STARTS HERE */ void push(int y){ if(top>MAXSIZE){ printf("\n stack is full"); }else{ top=top+1; st[top]=y; }display(); } /* PUSH FUNCTION ENDS HERE */ /* POP FUNCTION STARTS HERE */ void pop(){ int a; if(top<0){ printf("\n stack is empty"); }else{ st[top]; top--;

}display(); } /* POP FUNCTION ENDs HERE */ /* DISPLAY FUNCTION STARTS HERE */ void display(){ int j; for(j=top;j>=0;j--){ printf("\n |%d|",st[j]); } } /* DISPLAY FUNCTION ENDS HERE */

You might also like