1
2
3
4
5
6
7
8
9
10
11
12
13
#include "stack.h"
#define STACK_SIZE 100
static int sp = 0;
static int stack_buf[STACK_SIZE];
void push_val(int val) { if (sp < STACK_SIZE) stack_buf[sp++] = val; }
int pop_val() { return (sp > 0) ? stack_buf[--sp] : 0; }
void clear_stack() { sp = 0; }
int can_push() { return sp < STACK_SIZE; }
int can_pop() { return sp > 0; }