⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ss.cpp

📁 数据结构中所有算法的实现
💻 CPP
字号:
#include "d:\cpp\head.h"
#define INIT_SIZE 100
#define INCREMENT 10
typedef char ElemType;
typedef struct{
  ElemType *base;
  ElemType *top;
  int stacksize;
}SqStack;
Status InitStack(SqStack &S){
  S.base=(ElemType*)malloc(INIT_SIZE*sizeof(ElemType));
  if(!S.base)exit(OVERFLOW);
  S.top=S.base;
  S.stacksize=INIT_SIZE;
  return OK;
}
Status Push(SqStack &S,ElemType e){
  if(S.top-S.base>=S.stacksize){
    S.base=(ElemType*)realloc(S.base,(S.stacksize+INCREMENT)*sizeof(ElemType));
    if(!S.base)exit(OVERFLOW);
    S.top=S.base+S.stacksize;
    S.stacksize+=INCREMENT;
  }
  *S.top=e;
  S.top++;
  return OK;
}
Status Pop(SqStack &S,ElemType &e){
  if(S.top==S.base)return ERROR;
  S.top--;
  e=*S.top;
  return OK;
}
Status GetTop(SqStack &S,ElemType &e){
  if(S.top==S.base)return ERROR;
  e=*(S.top-1);
  return OK;
}
Bool StackEmpty(SqStack S){
  if(S.top==S.base)return TRUE;
  else return FALSE;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -