#include<stdio.h>
#include<stdlib.h>
#define MaxSize 50
typedef char ElemType;
typedef struct
{
ElemType data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack *&s) //初始化顺序栈
{
s=(SqStack *)malloc(sizeof(SqStack));
s->top=-1;
}
void DestroyStack(SqStack *&s) //销毁栈
{
free(s);
}
bool StackEmpty(SqStack *s) //判断栈是否为空
{
return(s->top==-1);
}
bool Push(SqStack *&s,ElemType e) //进栈
{
if(s->top==MaxSize-1)
return false;
else
s->top++;
s->data[s->top]=e;
return true;
}
bool Pop(SqStack *&s,ElemType e) //出栈
{
if(s->top==-1)
return false;
e=s->data[s->top];
s->top--;
return true;
}
bool GetTop(SqStack *s,ElemType &e) //取栈顶元素
{
if(s->top==-1)
return false;
e=s->data[s->top];
return true;
}
int main()
{
SqStack *s;
ElemType e;
InitStack(s);
StackEmpty(s);
Push(s,'a');
Push(s,'b');
Push(s,'c');
Push(s,'d');
Push(s,'e');
StackEmpty(s);
printf("输出出栈序列 ");
for(int i = 0; i < 5; i++)
{
printf("%c\t", Pop(s,e));
}
StackEmpty(s);
DestroyStack(s);
return 0;
}
这是数据结构的作业,前一个作业在关于线性表的作业输出第三个元素,输出的也是方块,有人能帮助我吗