棧的定義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;
- }