C program to perform push,pop and show in a Multiple Stack.
#define MAX 10 #include #include int stack[MAX],topA=-1,topB=MAX; void pushA(int no) { if(topA==topB) { printf("\n OVERFLOW"); return; } stack[++(topA)]=no; } int popA() { if(topA==-1) { printf("\n UNDERFLOW"); return -999; } return stack[(topA)--]; }
void showA() { int i; if(topA==-1) { printf("\n stack Empty"); return; } for(i=topA;i>=0;i--) { printf("\n %d",stack[i]); } }
void pushB(int no) { if(topB-1==topA) { printf("\n OVERFLOW"); return; } stack[--(topB)]=no; }
int popB() { if(topB==MAX) { printf("\n UNDERFLOW"); return -999; } return stack[(topB)--]; }
void showB() { int i; if(topB==MAX) { printf("\n stack Empty"); return; } for(i=topB;i{ printf("\n %d",stack[i]); } }
void main() { clrscr();
int ch,val; do { printf("\n\n\n 1 PUSH A"); printf("\n 2 PUSH B"); printf("\n 3 POP A"); printf("\n 4 POP B"); printf("\n 5 Show A"); printf("\n 6 Show B"); printf("\n 0 EXIT"); printf("\nENter your CHoice"); scanf("%d",&ch); switch(ch) { case 1:printf("\n enter Number"); scanf("%d",&val); pushA(val); break;
case 2: printf("\n enter Number"); scanf("%d",&val); pushB(val); break;
case 3: val=popA(); if(val!=-999) printf("%d popped",val); break;
case 4 : val=popB(); if(val!=-999) printf("%d popped",val); break;
case 5: showA(); break; case 6: showB(); break;
case 0:break; default:printf("\n Invalid choice"); } }while(ch!=0); getch(); }
|
No feedbacks found. Be the first to respond...
|