/* File: stacks.h Author: Jim Mayfield This file provides access to the standard stack routines developed in CMSC 202. To use it: 1. Typedef the type `stack_item_type' in your program. Stack_item_type MUST BE NO LARGER THAN A POINTER TYPE! (So it's OK to use `int' for stack_item_type, but not an array or a struct). You can put a call to check_stack_item_size() at the top of your main program to make sure your list_item_type is of an appropriate size. 2. #include "stacks.h" AFTER your definition of stack_item_type. 3. Compile your program so that it uses the 202 libraries. To do so, you will need add several items to your Makefile. Lines of the Makefile that create .o files will need to include `-I ~mayfield/lib202' immediately after the cc command, e.g.: cc -I ~mayfield/lib202 -g -c myfile.c Lines of the makefile that build executables will need to include `-L ~mayfield/lib202 -l202' immediately after the stack of .o files, e.g.: cc -o myprog myfile.o myfile_aux.o -L ~mayfield/lib202 -l202 */ #ifndef _CMSC_202_STACKS_ #define _CMSC_202_STACKS_ /* For check_stack_item_size: */ #include #include #include "basics.h" typedef struct stack_tag *stack_type; stack_type create_stack(void); BOOL empty_stack(stack_type stack); BOOL full_stack(stack_type stack); void push(stack_item_type item, stack_type stack); stack_item_type pop(stack_type stack); #define check_stack_item_size() do {if (sizeof(stack_item_type) > sizeof(void *)) { \ fprintf(stderr, "Stack error: stack_item_type is larger than a pointer.\n"); \ exit(EXIT_FAILURE); \ }} while (0) #endif