/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #include "stack2.h" typedef enum {false, true} bool; #define MAX 100 int stack_idx = 0; int stack[MAX]; void stack_push(int item) { if ( stack_idx < MAX ) { stack[stack_idx++] = item; } else { fprintf(stderr, "stack is full, returning.\n"); } } int stack_pop() { if ( stack_idx > 0 ) { return stack[--stack_idx]; } else { fprintf(stderr, "stack is empty, returning -1.\n"); return -1; } } int stack_empty() { return stack_idx > 0 ? 0 : 1; } int stack_full() { return stack_idx < MAX ? 0 : 1; }