?? stack.h
字號:
#include "malloc.h"
#define STACK_INT_SIZE 100;
#define STACKINCREMENT 10;
#define OK 1;
#define OVERFLOW 0;
#define ERROR 0;
typedef int SElemType;
typedef bool Status;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S)
{S.base=(SElemType *)malloc(100 * sizeof(SElemType));
//S.base=(SElemType *)malloc(STACK_INT_SIZE * sizeof(SElemType));
if(!S.base) return OVERFLOW ;
S.top=S.base;
S.stacksize=STACK_INT_SIZE;
return OK;
}
Status Push(SqStack &S,SElemType e)
{
if(S.top-S.base>=S.stacksize)
{S.base=(SElemType *)realloc(S.base,(S.stacksize+10) * sizeof(SElemType));
if(!S.base) return OVERFLOW;
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
return OK;
}
Status Pop(SqStack &S,SElemType &e)
{
if(S.top==S.base) return ERROR;
e=*--S.top;
return OK;
}
Status StackEmpty(SqStack &S)
{if(S.top==S.base) return 1;
else return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -