Advertisement
aleix616

Suma màxima dels camins d'un arbre general

Jun 17th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. static T i_max_suma_cami(node_arbreGen* n){
  2.     T max = 0;
  3.     if (n != NULL){
  4.         max = n->info;
  5.         T aux1 = 0;
  6.         for (int i = 0; i < n->seg.size(); i++){
  7.             T aux2 = i_max_suma_cami(n->seg[i]);
  8.             if (aux2 > aux1) aux1 = aux2;
  9.         }
  10.         max += aux1;
  11.     }
  12.     return max;
  13. }
  14.  
  15. T max_suma_cami() const
  16. /* Pre: el parametre implicit no es buit */
  17. /* Post: el resultat es la suma del cami de suma maxima del parametre implicit */
  18. {
  19.  
  20.     return i_max_suma_cami(primer_node);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement