/* File: trees.h Author: James Mayfield This file provides access to the standard binary tree routines developed in CMSC 202. To use it: 1. Typedef the type `tree_item_type' in your program. Tree_item_type MUST BE NO LARGER THAN A POINTER TYPE! (So it's OK to use `int' for tree_item_type, but not an array or a struct). You can put a call to check_tree_item_size() at the top of your main program to make sure your list_item_type is of an appropriate size. 2. #include "trees.h" AFTER your definition of tree_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 tree of .o files, e.g.: cc -o myprog myfile.o myfile_aux.o -L ~mayfield/lib202 -l202 */ #ifndef _CMSC_202_TREES_ #define _CMSC_202_TREES_ /* For check_tree_item_size: */ #include #include #include "basics.h" typedef struct tree_tag *tree_type; #define the_empty_tree NULL tree_type tree_cons(tree_item_type value, tree_type left, tree_type right); tree_item_type tree_data(tree_type tree); tree_type left_child(tree_type tree); tree_type right_child(tree_type tree); BOOL empty_tree(tree_type tree); #define check_tree_item_size() do { if (sizeof(tree_item_type) > sizeof(void *)) { \ fprintf(stderr, "Tree error: tree_item_type is larger than a pointer.\n"); \ exit(EXIT_FAILURE); \ }} while (0) #endif