Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pair<bool,string> Esquema::i_buscarAreaTematica1 (Arbre<string> &a, Revista& r, int& count, string& n) {
- pair<bool,string> p;
- // Base case: Empty tree don't have an Area
- if (a.es_buit()) {
- p.first = false;
- }
- else {
- n = a.arrel();
- // Look for the covered words in each child
- Arbre<string> a1, a2;
- a.fills(a1, a2);
- pair<bool,string> p1, p2;
- int count1, count2 = 0;
- string n1,n2;
- p1 = i_buscarAreaTematica1 (a1, r, count1, n1);
- p2 = i_buscarAreaTematica1 (a2, r, count2, n2);
- // If we covered all key words in left child, it is a possible area
- if (count1 >= r.longitudPalabrasClave() and p1.first == true) {
- p.first = true;
- p.second = n1;
- }
- // If we covered all key words in right child, it is a possible area
- if (count2 >= r.longitudPalabrasClave() and p2.first == true) {
- if (p.first == true and (p1.first == false or n2 < n1)) {
- // Child1 was already a solution but this one is better
- p.second = n2;
- }
- else if (p.first != true) {
- // we did not have a solution yet
- p.first = true;
- p.second = n2;
- }
- }
- // In case non of the children is the Area, increase the count with all the words covered so far
- if (p.first == false) {
- if (r.esPC(a.arrel())) {
- // The root contains a key word
- ++ count;
- }
- // Covered words = root +child1 + child2
- count = count + count1 + count2;
- }
- }
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement