#include <stdio.h>
#define datatype char
#define MAXSIZE 100
#define NULL '\0'
typedef struct
{
datatype data[MAXSIZE];
int top;
}SEQSTACK;
void initstack(SEQSTACK *s)
{
s->top=-1;
}
void push(SEQSTACK *s,datatype x)
{
if(s->top==MAXSIZE-1)
{
printf("overflow");
exit(0);
}
else
{
s->top++;
s->data[s->top]=x;
}
}
int empty(SEQSTACK *s)
{
if(s->top==-1)
{
return 1;
}
else
{
return 0;
}
}
datatype pop(SEQSTACK *s)
{
datatype x;
if(empty(s))
{
printf("underflow\n");
x=NULL;
}
else
{
x=s->data[s->top];
s->top--;
}
return x;
}
int main(int argc, char *argv[]) {
SEQSTACK s,*p;
char x,y;
p=&s;
initstack(p);
while((x=getchar())!='$')
{
push(p,x);
}
while(!empty(p))
{
y=pop(p);
printf("%3c",y);
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-39218.html