#include<stdio.h>
#include<stdlib.h>
#define MaxSize 10
//定义结构体
typedef struct SqStack{
char data[MaxSize];
int top;
}SqStack;
//初始化栈
void InitStack(SqStack *p){
p->top = -1;
}
//入栈
bool Push(SqStack *p,char x){
if(p->top == MaxSize-1)
return false;
p->top = p->top+1;
p->data[p->top] = x;
return true;
}
//出栈
bool Pop(SqStack *p,char &x){
if(p->top == -1)
return false;
x=p->data[p->top];
p->top = p->top-1;
return true;
}
//打印栈中元素
bool printStack(SqStack *p){
int topp = p->top;
while(p->top != -1){
printf("%c\n",p->data[p->top]);
p->top = p->top--;
}
p->top = topp;
return true;
}
int main(){
SqStack p;
InitStack(&p);
char x,y;
Push(&p,x);
Pop(&p,y);
printStack(&p);
return 0;
}
04-02
2126
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)