C语言实现顺序栈,并进行了封装,可保存命名为’SqStack.h’,即可调用
// Desc:顺序栈
// Time:20180819
// Vesion:0.0.1
#ifndef BASE
#define BASE
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int bool;
#endif
#ifndef STACK
#define STACK
#define STACK_INIT_SIZE 100
#define STACK_INCREASE_SIZE 10
typedef struct{
SElemType *base;
SElemType *top;
int size;
}SqStack;
// -- 初始化
Status InitStack(SqStack *pS) {
if ( !pS || pS->size>0 ) {
return ERROR;
}
pS->top = pS->base = (SElemType *)malloc(sizeof(SElemType)*STACK_INIT_SIZE);
if (!pS->base) {
exit(OVERFLOW);
}
pS->size = STACK_INIT_SIZE;
return OK;
}
// -- 销毁
Status DestroyStack(SqStack *pS) {
if (!pS) return