Exemplos de Algoritmos Básicos com Árvores: Difference between revisions

From Wiki**3

No edit summary
 
 
(No difference)

Latest revision as of 08:40, 12 November 2008

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);
   }