#include<iostream>
using namespace std;
typedef int SElemType;
typedef struct { //建立顺序栈存储结构
SElemType *base;
SElemType *top;
int stacksize;
}Sqstack;
int init(Sqstack &s,int maxsize) //初始化
{
s.base=new SElemType[maxsize];
if(!s.base)exit(1);
s.top=s.base;
s.stacksize=maxsize;
return 0;
}
int push(Sqstack &s,int e) //入栈
{
if(s.top-s.base==s.stacksize)return 0;
else{*s.top=e;
s.top++;}
return 0;
}
int pop(Sqstack &s) //出栈
{
int e;
if(s.top==s.base){return 0;}
else{e=*--s.top;}
return e;
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余4页未读,立即下载