栈的顺序存储

栈的定义ide

    限定仅在表尾进行插入和删除操做的线性表spa

栈的顺序存储结构指针

 

  
  
  
  
  1. #define MAXSIZE 20 
  2.  
  3. typedef int SElemType; 
  4. typedef struct
  5.     SElemType data[MAXSIZE]; 
  6.     int top;//栈顶指针,栈满时top为MAXSIZE-1,栈空时为-1  
  7. }SqStack;  

入栈blog

 

  
  
  
  
  1. bool push(SqStack *S,SElemType e){ 
  2.     if(S->top == MAXSIZE-1){//判断是否栈满  
  3.         return false
  4.     } 
  5.     S->data[++(S->top)] == e;//先上移再赋值  
  6.     return true

出栈get

 

  
  
  
  
  1. bool pop(SqStack *S,SElemType *e){ 
  2.     if(S->top == -1){ 
  3.         return false
  4.     } 
  5.      
  6.     *e = S->data[(S->top)--];//先赋值再下移 
  7.     return true; 
相关文章
相关标签/搜索