Stack program
#include<stdio.h>
#define n 100
struct node
{
int data[n];
int top;
};
void main()
{
int ch,i,no;
struct node s;
s.top=-1;
while(1)
{
printf("1.push");
printf("2.pop");
printf("3.display");
printf("4.exit");
scanf("%d",&no);
switch(ch)
{
case 1:
if(s.top==n-1)
printf("stack full");
else
{
printf("enter the nnumber");
scanf("%d",&no);
s.top++;
s.data[s.top]=no;
}break;
case 2:
if(s.top==-1)
printf("Stack is empty");
else
{
printf("%d",s.data[s.top]);
s.top--;
}
break;
case 3:
for(i=s.top;i>=0;i++)
printf("%d",s.data[i]);
break;
case 4:
return(0);
break;
}
}
No comments