栈:顺序栈和链表栈
#include <iostream>
#define OK 1
#define MAXSIZE 100
#define ERROR 0
#define OVERFLOW -1
typedef int Status
typedef int SElemtype
typedef struct {
SElemtype *base ;
SElemtype *top ;
int stacksize ;
}Sqstack;
Status InitStack(Sqstack &S){
S.base=new SElemtype[MAXSIZE];
if(!S.base) exit(OVERFLOW);
S.base=S.top;
S.stacksize=MAXSIZE;
return OK;
}
Status Push(Sqstack &S,SElemtype e){
if(S.top-S.base=S.stacksize) return ERROR; //栈满
*S.top++=e;
return OK;
}
Status Pop(Sqstack &S,SElemtype e){
if(S.top=S.base) return ERROR; //栈空
e=*S.top;
S.top--;
return;
}
SElemtype GetTop(Sqstack &S){
if(S.top=S.base) exit(1);
return*(S.top-1);
}
typedef struct Stacknode{
SElemtype data;
struct Stacknode *next;
}Stacknode,*Linkstack;
Status Iintstack(Linkstack &S){
S=NULL;
return OK;
}
Status Push(Linkstack &S,SElemtype e;){
p=new Stacknode;
p->data=e;
p->next=s;
S=p
retun OK;
}
Status Pop(Linkstack &S,SElemtype e);{
if(S==NULL) return ERROR;
e=S->data;
p=S;S=S->next;
delete p;
return OK;
}