/* stack1.c: A C implementation of a stack */

#include "stack1.h"

#define STACK_SIZE 100

static int stack[STACK_SIZE];
static int stkptr = 0;

void stack_init(void)
{
    stkptr = 0;
}

int stack_push(int x)
{
    return (stkptr == STACK_SIZE)
      ? STACK_ERROR
      : (stack[stkptr++] = x);
}

int stack_pop(void)
{
    return (stkptr == 0) ? STACK_ERROR : stack[--stkptr];
}
