/*************** BY Marxtudor www.marxtudor.com/ ***************/ #include#define MAX 5 void push(int); int pop(); void display(); int top = -1; int stk[MAX]; main() { int choice; int num; while(1) { printf("nEnter your choicen"); printf("1. Pushn"); printf("2. Popn"); printf("3. Displayn"); scanf("%d",&choice); switch(choice) { case 1: scanf("%d",&num); push(num); /*function call*/ break; case 2: pop(); /*function call*/ break; case 3: display(); /*function call*/ break; default: printf("nInvalid Inputn"); } /*end of switch*/ } /*end of while*/ } /*end of main*/ void push(int element) { if(top==MAX-1) { printf("nOverflown"); return; } top = top+1; stk[top]=element; } int pop() { int element; if(top==-1) { printf("nUnderflown"); return; } element = stk[top]; top = top-1; printf("%d deleted ", element); return element; } void display() { if(top==-1) { printf("nUnderflown"); return; } int i; printf("nn"); for(i=top; i>=0; i--) printf("%d n", stk[i]); }
1 Comment. Leave new
Thanks a lot .. nice program for beginners