//顺序栈是实现,是数据结构课本上的
#include <iostream>
using namespace std;
typedef int Elmtype;
//#define stacksize 100
#define SElemType int
#define STACK_INIT_SIZE 100
#define TRUE 1
#define FLASE 0
#define OK 1
#define ERROR 0
//#define OVERFLOW -2
#define INFEASIBLE -1
#define STACEINCREMENT 10
typedef int Status;
typedef struct
{
SElemType * base;
SElemType * top;
int stacksize;
}SqStack;
int Initstack(SqStack &s){
s.base=new Elmtype[STACK_INIT_SIZE];
if (!s.base)
exit(OVERFLOW);
s.top=s.base;
return 1;
}
int GetTop(SqStack s,SElemType &e){
if (s.top==s.top)
return ERROR;
e=*(s.top-1);
return OK;
}
int Push(SqStack &s,SElemType e){
/*if (s.top-s.base>=s.stacksize)
{
s.base=(SElemType*)realloc(s.base,(s.stacksize+STACEINCREMENT)*sizeof(SElemType));
if(!s.base) exit (OVERFLOW);
s.top=s.base+s.stacksize;
s.stacksize+=STACEINCREMENT;
}*/
*s.top=e;
s.top++;
return e;
}
int Pop(SqStack &s){
if (s.base==s.top)
return ERROR;
int e=*(s.top-1);
s.top=s.top-1;
return e;
}
int main(){
SqStack s;
Initstack(s);
Push(s,3);
cout<<"HEllo"<<endl;
cout<<Pop(s);
}