#include <iostream>
using namespace std;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct{
int * base;
int * top;
int stacksize;
}SqStack;
int InitStack(SqStack & S)
{
S.base=(int*) malloc (STACK_INIT_SIZE * sizeof(int));
if(!S.base) exit(-1);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return 1;
}
int Push(SqStack &S,int e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(int*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
if(!S.base)exit(-1);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
return 1;
}
int Pop(SqStack &S,int & e)
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载