diff tree2/tree.c tree3/tree.c 3,4c3,4 < * (introduces typedef) < * --- > * (store arbitrary 'things' using void*) > * 15,16d14 < const int TREE_KEY_NOT_FOUND = -1; // used by tree_find() < 20c18 < int data; // data for this item --- > void *data; // pointer to data for this item 31c29 < tree_new(const int key, const int data) --- > tree_new(const int key, void *data) 51,52c49,50 < * If the key is already in the tree, its datum is update with new data; < * the key should not be TREE_KEY_NOT_FOUND. --- > * If the key is already in the tree, its datum is update with new data. > * (The result is that old data pointer is lost.) 55c53 < tree_insert(tree_t *node, const int key, const int data) --- > tree_insert(tree_t *node, const int key, void *data) 78c76 < * return TREE_KEY_NOT_FOUND if key is not in tree. --- > * return NULL if key is not in tree. 80c78 < int --- > void * 84c82 < return TREE_KEY_NOT_FOUND; --- > return NULL; diff tree2/tree.h tree3/tree.h 3c3 < * (introduces typedef) --- > * (store arbitrary 'things' using void*) 19c19 < tree_t *tree_new(const int key, int data); --- > tree_t *tree_new(const int key, void *data); 25c25 < * the key should not be TREE_KEY_NOT_FOUND. --- > * the key should not be tree_t_KEY_NOT_FOUND. 27c27 < tree_t *tree_insert(tree_t *root, const int key, const int data); --- > tree_t *tree_insert(tree_t *root, const int key, void *data); 30c30 < * return TREE_KEY_NOT_FOUND if key is not in tree. --- > * return tree_t_KEY_NOT_FOUND if key is not in tree. 32,33c32 < int tree_find(tree_t *root, const int key); < extern const int TREE_KEY_NOT_FOUND; --- > void *tree_find(tree_t *root, const int key); diff tree2/treetest.c tree3/treetest.c 20a21,22 > char datastring[] = "Test data"; > 22,30c24,32 < root = tree_insert(root, 3, 9); < root = tree_insert(root, 4, 9); < root = tree_insert(root, 1, 9); < root = tree_insert(root, 5, 9); < root = tree_insert(root, 6, 9); < root = tree_insert(root, 2, 9); < root = tree_insert(root, 8, 9); < root = tree_insert(root, 7, 9); < root = tree_insert(root, 0, 9); --- > root = tree_insert(root, 3, datastring); > root = tree_insert(root, 4, datastring); > root = tree_insert(root, 1, datastring); > root = tree_insert(root, 5, datastring); > root = tree_insert(root, 6, datastring); > root = tree_insert(root, 2, datastring); > root = tree_insert(root, 8, datastring); > root = tree_insert(root, 7, datastring); > root = tree_insert(root, 0, datastring); 32,33c34,35 < printf("find %d returns %d\n", 4, tree_find(root, 4)); < printf("find %d returns %d\n", 5, tree_find(root, 5)); --- > printf("find %d returns %s\n", 4, tree_find(root, 4)); > printf("find %d returns %s\n", 5, tree_find(root, 5)); 36,37c38,39 < root = tree_insert(root, 5, 99); < printf("find %d returns %d\n", 5, tree_find(root, 5)); --- > root = tree_insert(root, 5, "new string"); > printf("find %d returns %s\n", 5, tree_find(root, 5));