//栈的顺序存储类型描述
#define MaxSize 50
typedef struct{
ElemType data[MaxSize];
int top;
}SqStack;
//初始化
void InitStack(&S){
S.top=-1;
}
//判断栈空
bool StackEmpty(S){
if(S.top==1)
return true;
else
return false;
}
//进栈
bool Push(SqStack &S,ElemType x){
if(S.top==MaxSize-1)
return false;
S.data[++S.top]=x;
return true;
}
//出栈
bool Pop(Sqstack &S,ElemType &x){
if(S.top==-1)
return false;
x=S.data[S.top--];
return true;
}
//读栈顶元素
bool GetTop(SqStack S,ElemType *x){
if(S.top==-1)
return false;
x=S.data[S.top];
return true;
}
//栈的链式存储类型描述
typedef struct LinkNode{
ElemType data;
struct LinkNode *next;
}LiStack;
栈
最新推荐文章于 2024-08-06 16:30:57 发布