#include<stdio.h>
#define MAXSIZE 8
#define ERROR 0
#define Status int
#define SUCCESS 1
typedef struct stack{
int data[MAXSIZE];
int top;
}*Stack;
void initStack(Stack &stack){
stack->top = -1;
}
Status isEmpty(Stack stack){
if(stack->top == -1){
return 1;
}else{
return 0;
}
}
Status isFull(Stack stack){
if(stack->top == MAXSIZE - 1){
return 1;
}else{
return 0;
}
}
Status add(Stack &stack,int data){
if(isFull(stack)){
return ERROR;
}
stack->top++;
stack->data[stack->top] = data;
return SUCCESS;
}
Status get(Stack stack,int &data){
if(isEmpty(stack)){
data = -1;
return ERROR;
}
data = stack->data[stack->top];
stack->top--;
return SUCCESS;
}
int main(){
Stack stacks = new stack;
initStack(stacks);
add(stacks,1);
add(stacks,2);
add(stacks,3);
int data;
get(stacks,data);
printf("%d\n",data);
get(stacks,data);
printf("%d\n",data);
get(stacks,data);
printf("%d\n",data);
get(stacks,data);
printf("%d\n",data);
}