1: /* $Header$ */ 2: 3: /* 4: * Author: Peter J. Nicklin 5: */ 6: 7: /* 8: * treesearch() returns the number of occurrences of a key in a binary tree. 9: */ 10: #include "tree.h" 11: #include "null.h" 12: 13: treesearch(p, key) 14: TREE *p; /* current node pointer */ 15: char *key; /* pointer to key */ 16: { 17: int comp; /* compare key values */ 18: int strcmp(); /* string comparison */ 19: 20: if (p != NULL) 21: { 22: if ((comp = strcmp(key, p->key)) < 0) 23: return(treesearch(p->left, key)); 24: else if (comp > 0) 25: return(treesearch(p->right, key)); 26: else 27: return(p->count); 28: } 29: return(0); 30: }