#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
#define ERROR -1000000
typedef struct Stack* _stack;
struct Stack
{
int element[MAXSIZE];
int top;
};
void InitStack(_stack stack) //初始化
{
stack->top = -1;
}
void Push(_stack stack, int e) //进栈
{
if (stack->top >= MAXSIZE - 1)
{
printf("栈满\n");
return ERROR;
}
else
{
(stack->top)++;
stack->element[stack->top] = e;
}
}
int Pop(_stack stack) //出栈
{
if (stack->top <= -1)
{
printf("栈空\n");
return ERROR;
}
else
{
return stack->element[(stack->top)--];
}
}
int main(void)
{
_stack stack = (_stack)malloc(sizeof(struct Stack));
InitStack(stack);
Push(stack, 2);
Push(stack, 3);
Push(stack, 4);
printf("%d\n", Pop(stack));
printf("%d\n", Pop(stack));
printf("%d\n", Pop(stack));
return 0;
}