📄 stack.cpp
字号:
#include <iostream>
#include "stack.h"
using namespace std;
Status Stack<char>::InitStack(){
base=new SElemType[STACK_INIT_SIZE];
if(!base) exit(OVERFLOW);
top=base;
stacksize=STACK_INIT_SIZE;
return OK;
}
Status Stack<char>::GetTop(SElemType &e){
if(top==base) return ERROR;
e=*(top-1);
return OK;
}
Status Stack<char>::Push(SElemType e){
SElemType *newbase=0;
int i;
if(top-base>=stacksize){
newbase=new SElemType[stacksize+STACKINCREMENT];
if(!newbase) exit(OVERFLOW);
for(i=0;i<stacksize;i++)
newbase[i]=base[i];
delete [] base;
base=newbase;
top=base+stacksize;
stacksize=stacksize+STACKINCREMENT;
}
*top++=e;
return OK;
}
Status Stack<char>::Pop(SElemType &e){
if(base==top) return ERROR;
e=*--top;
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -