#include<stdio.h>
#include<stdlib.h>
#define MaxSize 10
#define true 1
#define false 0
typedef int ElemType;
typedef int bool;
typedef struct {
ElemType data[MaxSize];
int top;
}Stack,*SqStack;
//初始化栈
bool InitStack(SqStack *S) {
*S = (SqStack)malloc(sizeof(Stack));
(*S)->top = -1;
}
//压栈
bool Push(SqStack S,ElemType e) {
if (S->top == MaxSize - 1) {
return false;
}
S->top = S->top + 1;
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;
}
//销毁栈
bool DestroyStack(SqStack S) {
free(S);
}
//判断空栈
bool ISEmpty(SqStack S){
if (S->top == -1) {
return true;
}
return false;
}
//判断栈满
bool IsFull(SqStack S) {
if (S->top == MaxSize - 1) {
return true;
}
return false;
}
//进行测试
int main() {
SqStack S;
InitStack(&S);
Push(S,1);
int e;
Pop(S, &e);
printf("%d\n",e);
DestroyStack(S);
system("pause");
return 0;
}