#include<stdio.h>
#include<math.h>
#define STACK_SIZE 100 /* 栈初始向量大小 */
#define STACKINCREMENT 10 /* 存储空间分配增量 */
#define OK 1
#define ERROR -1
typedef int Status ;
typedef int ElemType ;
typedef struct sqstack
{
ElemType *bottom; /* 栈不存在时值为NULL */
ElemType *top; /* 栈顶指针 */
int stacksize ; /* 当前已分配空间,以元素为单位 */
} SqStack ;
// 栈的初始化
SqStack Init_Stack(){
SqStack S ;
// 动态分配空间
S.bottom=(ElemType *)malloc(STACK_SIZE*sizeof( ElemType ));
// S.bottom不为空时,返回error
// if (! S.bottom)
// return ERROR;
// 栈列表为空是,top指针和bottom指针指向同一个地址
S.top=S.bottom ; /* 栈空时栈顶和栈底指针相同 */
// 大小为100
S.stacksize=STACK_SIZE;
return S ;
}
C语言动态存储栈的初始化
最新推荐文章于 2021-11-28 21:06:06 发布