1.顺序栈的基本操作
typedef struct {
//顺序栈的数据类型
ElemType data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack*& s)//初始化顺序栈
{
s = new SqStack;
s->top = -1;
}
bool StackEmpty(SqStack* s)//判断栈是否为空
{
return(s->top == -1);
}
void DestoryStack(SqStack* s)//销毁栈
{
delete s;
}
bool Push(SqStack*& s, ElemType e)//进栈
{
if (s->top == MaxSize - 1)
return false;
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;
}
2.链栈的基本操作
typedef int ElemType;
typedef struct