Advertisement
jonator

Crit1

Dec 4th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. Paraula Esquema::i_buscarAreaTematica1 (Arbre<string> &a, Revista& r, int& altura, int& nMax) {
  2.     Paraula p;
  3.     if (a.es_buit()) {
  4.       p.es = false;
  5.       altura = 0;
  6.     }
  7.     else if (r.esPC(a.arrel())) {
  8.       p.es = true;
  9.       p.nom = a.arrel();
  10.       altura = 1;
  11.     }
  12.     else {
  13.       Arbre<string> a1, a2;
  14.       a.fills(a1, a2);
  15.       Paraula p1, p2;
  16.       int x,y;
  17.       p1 = i_buscarAreaTematica1 (a1, r, x, nMax);
  18.       p2 = i_buscarAreaTematica1 (a2, r, y, nMax);
  19.       if (p1.es and not p2.es) {
  20.     p.es = true;
  21.     if (r.esPC(p1.nom)) {
  22.       p.nom = a.arrel();
  23.       p.altura = x+1;
  24.     }
  25.     else {
  26.       p.nom = p1.nom;
  27.       p.altura = p1.altura;
  28.     }
  29.       }
  30.       else if (not p1.es and p2.es) {
  31.     p.es = true;
  32.     if (r.esPC(p2.nom)) {
  33.       p.nom = a.arrel();
  34.       p.altura = y+1;
  35.     }
  36.     else {
  37.       p.nom = p2.nom;
  38.       p.altura = p2.altura;
  39.     }
  40.       }
  41.       else if (p1.es and p2.es) {
  42.     p.es = true;
  43.     if (r.esPC(p1.nom) and not r.esPC(p2.nom)) {
  44.       p.nom = a.arrel();
  45.       p.altura = x+1;
  46.     }
  47.     else if (not r.esPC(p1.nom) and r.esPC(p2.nom)) {
  48.       p.nom = a.arrel();
  49.       p.altura = y+1;
  50.     }
  51.     else if (r.esPC(p1.nom) and r.esPC(p2.nom)) {
  52.       p.nom = a.arrel();
  53.       if (x >= y)
  54.         p.altura = x+1;
  55.       else
  56.         p.altura = y+1;
  57.     }
  58.     else {
  59.       p.es = true;
  60.       if ((nMax - p1.altura) == (nMax - p2.altura)) {
  61.         if (p1.nom.compare(p2.nom) <= 0) {
  62.           p.nom = p1.nom;
  63.           p.altura = p1.altura;
  64.         }
  65.         else {
  66.           p.nom = p2.nom;
  67.           p.altura = p2.altura;
  68.         }
  69.       }
  70.       else if ((nMax - p1.altura) > (nMax - p2.altura)) {
  71.         p.nom = p1.nom;
  72.         p.altura = p1.altura;
  73.       }
  74.       else {
  75.         p.nom = p2.nom;
  76.         p.altura = p2.altura;
  77.       }
  78.     }
  79.       }
  80.       else {
  81.     p.es = false;
  82.       }
  83.       if (x >= y)
  84.     altura = x+1;
  85.       else
  86.     altura = y+1;
  87.     }
  88.     return p;
  89.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement