#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>
#define MaxSize 16
#define EnlargeMemary 16
typedef struct stack {
int* stack_top;
int* stack_bottom;
int size = MaxSize;
}stk;//stack
void creat_stack(stk*&target) {
target = (stk*)malloc(sizeof(stk));
assert(target);
target->size = MaxSize;
target->stack_bottom = (int *)malloc(sizeof(int) * MaxSize);
assert(target->stack_bottom);
target->stack_top = target->stack_bottom;
}//创建栈
bool Judge_if_full(stk*& target) {
if (target->stack_top - target->stack_bottom == 0)
return true;
return false;
}//判断栈满?
void Enlarge_memary(stk*&target) {
int* a = (int*)realloc(target->stack_bottom, (target->size + EnlargeMemary)*sizeof(int));
assert(a);
target->size += EnlargeMemary;
target->stack_bottom = a;
target->stack_top = target->stack_bottom + target->size;
}//栈扩容
bool Judge_if_null(stk*&target)
{
if (target->stack_bottom == target->stack_top)return true;
else return false;
}//判断栈空?
void Input_stack(stk*&target,int value)
{
if (!target)
creat_stack(target);
if (Judge_if_full(target))
Enlarge_memary(target);
*(target->stack_top) = value;
target->stack_top += 1;
}//入栈
int Output_stack(stk*& target) {
if(!Judge_if_null(target))
return 0;
int temp = *(target->stack_top);
target->stack_top -= 1;
return temp;
}//出栈