顺序栈的基本类型定义:
typedef struct{
SElemType *base;
int top;
int stacksize;
}SqStack;
前提工作:提供realloc函数:
template <class T>
T* realloc_p(T* a,int Size){
T *t;
t=new T [Size];
memcpy(t,a,Size*sizeof(T));
delete []a;
return t;
}
顺序栈的基本操作:
1、初始化操作InitStack
//初始化操作
void InitStack(SqStack &S){
S.base=new SElemType [StackInitSize];
S.top=0;
S.stacksize=StackInitSize;
}
2、判断一个顺序栈是否为空栈StackEmpty
//判断一个顺序栈是否为空栈
bool StackEmpty(SqStack S){
return S.top?false:true;
}
3、求顺序栈的长度StackLength
//求顺序栈的长度
int StackLength(SqStack S){