栈是后进先出,像弹夹一样

#include<stdio.h>
#include<stdlib.h>
#define max 100
typedef int ElemType;

typedef struct {
ElemType data[max];
int top;
}Stack;

//初始化
void initStack(Stack* s) {
s->top = -1;
}

//压栈/进栈
int push(Stack* s, ElemType e) {
if (s->top >= max - 1) {
printf(“满了\n”);
return 0;
}
s->top++;
s->data[s->top] = e;
return 1;
}

//出栈
int pop(Stack s, ElemType e){
if (s->top == -1) {
printf(“空的”);
return 0;
}
*e = s->data[s->top];
s->top–;
return 1;
}

int main() {
Stack s;
initStack(&s);
push(&s, 10);
push(&s, 20);
push(&s, 30);
ElemType e;
pop(&s, &e);
printf(“%d\n”, e);
return 0;
}