#include <stdio.h>
#include <stdlib.h>
#define MaxSize 20
#define false0
#define true1;
typedef struct SqStack{
int data[MaxSize];
int top;}SqStack;voidInitStack(SqStack *S){//初始化顺序栈S->top=-1;}
int Push(SqStack *S,int n){//将数据n压入栈中if(S->top==MaxSize-1)returnfalse;S->top++;S->data[S->top]=n;printf("元素%d进栈成功\n",n);returntrue;}
int StackEmpty(SqStack S){//判断是否为空if(S.top ==-1){printf("此栈为空\n");returntrue;}else{printf("此栈不为空\n");returnfalse;}}
int Pop(SqStack *S,int *a){//栈顶元素出栈,且将数据存储在a中
int i=S->top;if(S->top==-1){returnfalse;}*a=S->data[i];S->top--;printf("出栈的数据为:%d\n",*a);returntrue;}
int GetTop(SqStack S){if(S.top !=-1){printf("栈顶元素为:%d\n",S.data[S.top]);returntrue;}elsereturnfalse;}
int Display(SqStack S){printf("此栈中的元素为:");for(int i=0; i<=S.top; i++){printf("%d",S.data[i]);}printf("\n");returntrue;}
int main(){
SqStack S;InitStack(&S);//初始化一个空栈Push(&S,3);//将3进栈Push(&S,4);//将4进栈Display(S);//输出栈中元素
int n;Pop(&S,&n);//将栈顶元素出栈,且将元素赋给nStackEmpty(S);//判断是否为空GetTop(S);//获得栈顶元素}