/**********************************************************************/ /* Howard Eng 9/93 */ /* */ /* Header for tree.c. */ /* */ /**********************************************************************/ #ifndef _TREE #define _TREE typedef struct tree_st { char *data; struct tree_st *left; struct tree_st *right; } tree; /**********************************************************************/ /* */ /* add_to_tree() - Adds an item to the tree. */ /* get_from_tree() - Finds an item from a tree. Returns (char *) */ /* NULL if not found */ /* walk_tree() - Walks a tree and performs (*func)( tree, data )*/ /* at each node. */ /* The tree is walked in sorted order, and the */ /* data argument allows arbitrary data to be */ /* passed to func. */ /* */ /* root_node - Root of the binary tree. It must be static and*/ /* initialized to (tree *) NULL. Calls to */ /* add_to_tree() require the address of root_node */ /* (e.g., &root_node ). The first call to add_to_*/ /* tree() forces root_node to point to the first */ /* stored item. */ /* */ /* data - pointer to the item that needs to be stored. */ /* */ /* comp - comparison function. This is used to determine*/ /* whether data gets stored to the "left" or */ /* "right" of the current node. */ /* comp must return -1 if the current node < data;*/ /* 0 if the current_node == data*/ /* 1 if the current_node > data */ /* */ /**********************************************************************/ void ada_thd_add_to_tree( tree **root_node, char *data, int (*comp)( tree *, void * ) ); char *ada_thd_get_from_tree( tree *root_node, char *data, int (*comp)( tree *, void * ) ); void ada_thd_walk_tree( tree *root_node, void (*func)( tree *, char * ), char * ); #endif