栈的定义ide
限定仅在表尾进行插入和删除操做的线性表spa
栈的顺序存储结构指针
- #define MAXSIZE 20
- typedef int SElemType;
- typedef struct{
- SElemType data[MAXSIZE];
- int top;//栈顶指针,栈满时top为MAXSIZE-1,栈空时为-1
- }SqStack;
入栈blog
- bool push(SqStack *S,SElemType e){
- if(S->top == MAXSIZE-1){//判断是否栈满
- return false;
- }
- S->data[++(S->top)] == e;//先上移再赋值
- return true;
- }
出栈get
- bool pop(SqStack *S,SElemType *e){
- if(S->top == -1){
- return false;
- }
- *e = S->data[(S->top)--];//先赋值再下移
- return true;
- }