Exemplos de Algoritmos Básicos com Árvores

From Wiki**3

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Contagem de elementos de uma árvore binária.

   size_t count(link h) {
     if (!h) return 0;
     return 1 + count(h->l) + count(h->r);    
   }

Cálculo da altura de uma árvore binária.

   size_t height(link h) {
     int hl, hr;
     if (!h) return 0;
     hl = height(h->l);
     hr = height(h->r);
     return 1 + max(hl, hr);
   }