Beispiel #1
0
/* returns number of entries in bst t */ 
unsigned int bst_num_entries(bst *t)
{
    int sum = 0; 
    if(t != NULL)  
	sum++; 
    if(t -> lsub != NULL) 
	sum += bst_num_entries(t -> lsub); 
    if(t -> rsub != NULL) 
	sum += bst_num_entries(t -> rsub); 
    return sum; 
}
Beispiel #2
0
Datei: bst.c Projekt: gaibo/C
unsigned int bst_num_entries(bst *t)
{
    // special case: empty tree given
    if (t == NULL) {
        return 0;
    }
    
    // base case: leaf node (singleton tree)
    if (t->lsub == NULL && t->rsub == NULL) {
        return 1;
    }
    
    // recursive step
    return 1 + bst_num_entries(t->lsub) + bst_num_entries(t->rsub);
}
Beispiel #3
0
Datei: main.c Projekt: gaibo/C
void addr_book_stats(bst *abk)
{
  fprintf(stdout, "* entries in address book:      %d\n", 
	  bst_num_entries(abk));
  fprintf(stdout, "* height of binary search tree: %d\n", 
	  bst_height(abk));
  putchar('\n');
}