Advertisement
jonator

Crit 1

Dec 5th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. pair<bool,string> Esquema::i_buscarAreaTematica1 (Arbre<string> &a, Revista& r, int& count, string& n) {
  2.     pair<bool,string> p;
  3.     // Base case: Empty tree don't have an Area
  4.     if (a.es_buit()) {      
  5.       p.first = false;
  6.     }
  7.     else {         
  8.       n = a.arrel();
  9.       // Look for the covered words in each child
  10.       Arbre<string> a1, a2;
  11.       a.fills(a1, a2);
  12.       pair<bool,string> p1, p2;
  13.       int count1, count2 = 0;
  14.       string n1,n2;
  15.       p1 = i_buscarAreaTematica1 (a1, r, count1, n1);
  16.       p2 = i_buscarAreaTematica1 (a2, r, count2, n2);
  17.       // If we covered all key words in left child, it is a possible area
  18.       if (count1 >= r.longitudPalabrasClave() and p1.first == true) {
  19.       p.first = true;
  20.       p.second = n1;          
  21.       }
  22.       // If we covered all key words in right child, it is a possible area
  23.       if (count2 >= r.longitudPalabrasClave() and p2.first == true) {
  24.           if (p.first == true and (p1.first == false or n2 < n1)) {
  25.          // Child1 was already a solution but this one is better
  26.              p.second = n2;
  27.           }
  28.           else if (p.first != true) {
  29.          // we did not have a solution yet
  30.              p.first = true;
  31.              p.second = n2;
  32.           }
  33.       }
  34.       // In case non of the children is the Area, increase the count with all the words covered so far
  35.       if (p.first == false) {
  36.           if (r.esPC(a.arrel())) {
  37.              // The root contains a key word
  38.              ++ count;
  39.           }
  40.       // Covered words = root +child1 + child2
  41.           count = count + count1 + count2;
  42.       }
  43.     }
  44.     return p;
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement