实现代码
#include<stdio.h>
#include<stdlib.h>
#define MaxSize 10
typedef int ElemType;
typedef struct{
ElemType data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack *&s){
s = (SqStack *)malloc(sizeof(SqStack));
s->top=-1;
}
bool Push(SqStack *&s,ElemType e){
if(MaxSize-1==s->top)
return false;
s->data[++s->top]=e;
return true;
}
bool Pop(SqStack *&s,ElemType &e){
if(s->top==-1)
return false;
e=s->data[s->top--];
return true;
}
bool GetTop(SqStack *s , ElemType &e){
if(s->top==-1)
return false;
e=s->data[s->top];
return true;
}
int main(){
SqStack *s;
InitStack(s);
Push(s,1);
Push(s,2);
Push(s,3);
Push(s,34);
for(int i=0;i<4;i++){
ElemType e;
Pop(s,e);
printf("%d\n",e);
}
}