//顺序栈:头入头出,top,base
#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
#define MAXSIZE 10
typedef int Status;
typedef int SElemType;
typedef struct{
SElemType *top;
SElemType *base;
}SqStack;
Status InitStack(SqStack &S){
S.base= new SElemType [MAXSIZE];
S.top=S.base;
return OK;
}
Status Push(SqStack &S,SElemType e){
if(S.top-S.base==MAXSIZE) return ERROR;
*S.top++=e;
return OK;
}
Status Pop(SqStack &S,SElemType &e){
if(S.top==S.base) return ERROR;
e=*--S.top;
return OK;
}
int main(){
SqStack S;
InitStack(S);
Push(S,1);
Push(S,2);
SElemType e;
Pop(S,e);
cout<<e<<" ";
}
数据结构:顺序栈
于 2023-11-30 16:58:46 首次发布