typedef struct Stack_T {
int *stk; // 也可以用固定值
int cnt;
} Stack_S;
Stack_S g_stack = {0};
void StackInit(int size) {
g_stack.cnt = 0;
g_stack.stk = (int *)malloc(sizeof(int) * size);
}
void StackFree() {
g_stack.cnt = 0;
free(g_stack.stk);
g_stack.stk = NULL;
}
bool StackEmpty() {
return (g_stack.cnt == 0);
}
int StackTop() {
if (StackEmpty()) {return -1;}
return g_stack.stk[g_stack.cnt - 1];
}
int StackPop() {
if (StackEmpty()) {return -1;}
g_stack.cnt--;
return g_stack.stk[g_stack.cnt];
}
void StackPush(int val) {
g_stack.stk[g_stack.cnt] = val;
g_stack.cnt++;
}