#define MAX 10
typedef struct stack
{
char data[MAX];
int top;
}stack;
void init(stack *s)
{ s->top=-1;
}
int empty(stack *s)
{ if(s->top==-1)
return(1);
return(0);
}
int full(stack *s)
{ if(s->top==MAX-1)
return(1);
return(0);
}
void push(stack *s,char x)
{
s->top=s->top+1;
s->data[s->top]=x;
}
char pop(stack *s)
{
char x;
x=s->data[s->top];
s->top=s->top-1;
return(x);
}
void print(stack *s)
{ int i;
printf("\n");
for(i=s->top;i>=0;i--)
printf("%c ",s->data[i]);
}
No comments:
Post a Comment