2019年06月17日
阅读 607
评论 0
喜欢 0
顺序栈的存储结构
#define MaxSize 100
typedef int ElemType;
struct SqStack {
ElemType data[MaxSize];
int top;
};
初始化栈的算法
void InitStack(SqStack &st) {
st.top=-1;
}
判断栈空的算法
int StackEmpty(SqStack st) {
return (st.top==-1);
}
进栈算法
int Push(SqStack &st,ElemType x) {
if(st.top==MaxSize-1)
return 0;
st.top++;
st.data[st.top]=x;
return 1;
}
出栈算法
int Pop(SqStack &st,ElemType &x) {
if(st.top==-1)
return 0;
x=st.data[st.top];
st.top--;
return 1;
}
取栈顶元素算法
int GetTop(SqStack &st,ElemType &x) {
if(st.top==-1)
return 0;
x=st.data[st.top];
return 1;
}
暂无评论