栈的定义
#include <iostream>
#define MAXSIZE 1000
using namespace std;
typedef struct
{
int data[MAXSIZE];
int top;
}SqStack;
栈的操作
初始化
bool initStack(SqStack &st)
{
st.top = -1;
return true;
}
判断为空
bool isEmpty(SqStack st)
{
if(st.top == -1)
return true;
else
return false;
}
入栈
bool pushStack(SqStack &st, int e)
{
if(st.top == MAXSIZE - 1)
return false;
st.top++;
st.data[st.top] = e;
return true;
}
出栈
bool popStack(SqStack &st, int &e)
{
if(st.top == -1)
return false;
e = st.data[st.top];
st.top--;
return true;
}
获取栈顶元素
bool getStackTopElem(SqStack st, int &e)
{
if(st.top == -1)
return false;
e = st.data[st.top];
return true;
}