Last active
September 13, 2017 06:45
-
-
Save imran-parray/5c26c735b6aa85d9bc946689588de0d5 to your computer and use it in GitHub Desktop.
7-Multiple stack in Single Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define max 12 | |
int st[max],n,top[5],tos[5],buttom[5],ch,sn,ele,i,size,item; | |
void main() | |
{ | |
printf("Enter The Number of Stack \n"); | |
scanf("%d",&n); | |
size=max/n; | |
buttom[0]=-1; | |
for(i=1;i<n;i++) | |
buttom[i]=buttom[i-1]+size; | |
for(i=0;i<n;i++) | |
tos[i]=buttom[i]; | |
for(i=0;i<n;i++) | |
top[i]=buttom[i]+size; | |
do{ | |
printf("\n 1-PUSH \n 2-POP \n 3-Display \n 4-Exit \n\n"); | |
scanf("%d",&ch); | |
switch(ch) | |
{ | |
case 1: printf("Enter The Stack Number to PUSH \n"); | |
scanf("%d",&sn); | |
printf("Enter The element \n"); | |
scanf("%d",&ele); | |
push(sn,ele); | |
break; | |
case 2 :printf("Enter The Stack Number POP \n"); | |
scanf("%d",&sn); | |
pop (sn); | |
break; | |
case 3: printf("Enter The Stack Number To Display \n"); | |
scanf("%d",&sn); | |
disp(sn); | |
break; | |
} | |
}while(ch<=3); | |
} | |
//PUSH FUCNTION | |
void push(int sn,int ele) | |
{ | |
if (tos[sn]==top[sn]) | |
printf("Stact %d is Overflowing \n",sn); | |
else | |
st[++tos[sn]]=ele; | |
} | |
//POP FUNCTION | |
void pop(int sn) | |
{ | |
if (tos[sn]==buttom[sn]) | |
printf("The Stack %d is in Underflow Condition \n",sn); | |
else | |
item=tos[sn]; | |
tos[sn]--; | |
printf("Element Popped is "); | |
} | |
//Display FUNCTION | |
void disp(int sn) | |
{ | |
if (tos[sn]==buttom[sn]) | |
printf("Nothing to Show :-( stack is Empty \n"); | |
else | |
for (i=tos[sn];i>buttom[sn];i--) | |
printf("Elements are : %d \t",st[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment