目录
1.创建SqStack.cpp文件
#include <stdio.h>
//声明顺序栈
//顺序栈的初始分配空间大小
#define MaxSize 100
//声明顺序栈中的元素为字符类型
typedef char ElemType;
typedef struct
{
//保存顺序栈中元素
ElemType data[MaxSize];
//栈顶指针
int top;
}SqStack;
//初始化
//st为引用型参数
void InitStack(SqStack &st)
{
st.top=-1;
}
//销毁栈
void DestroyStack(SqStack st)
{
}
//进 栈
int Push(SqStack &st,ElemType x)
{
if(st.top==MaxSize-1)
//栈满上溢出返回0
return 0;
else{
st.top++;
st.data[st.top]=x;
//成功进栈返回1
return 1;
}
}
//出栈
//x为引用类型参数
int Pop(SqStack &st,ElemType &x)
{
if(st.top==-1)
//栈空返回0
return 0;
else{
x=st