#include<stdio.h>
#include<stdlib.h>
#define stacksize 100
typedef char datatype;
typedef struct
{
datatype data[stacksize];
int top;
}seqstack;
seqstack *initstack(seqstack *s)
{
s = (seqstack *)
malloc(
sizeof(seqstack));
s->top = -
1;
return s;
}
int stackempty(seqstack *s)
{
if (s->top == -
1)
return 1;
else
return 0;
}
int stackfull(seqstack *s)
{
if (s->top == stacksize -
1)
return 1;
else
return 0;
}
int push(seqstack *s,
int x)
{
if (stackfull(s))
{
printf(
"error,stack overflow\n");
return 0;
}
s->data[++s->top] = x;
return 1;
}
int pop(seqstack *s,
int *x)
{
if (stackempty(s))
{
printf(
"error,stack underflow\n");
return 0;
}
*x = s->data[s->top];
s->top--;
return 1;
}
int stacktop(seqstack *s)
{
if (stackempty(s))
{
printf(
"error, stack is empty\n");
return 0;
}
return (s->data[s->top]);
}