int Organigrama::assign_offi_less_level(Arbre<int> &a, Agenda &agenda, int day, int& level_aux, int level, bool &found, int& depth) { int id; if (level_aux <= level and not a.es_buit()) { int root = a.arrel(); int id_cita; agenda.consultar_cita(root, day, id_cita); if (id_cita == 0) { found = true; depth = 0; id = root; } else { ++level_aux; Arbre<int> a1, a2; a.fills(a1, a2); int depth1, depth2; bool found1, found2; int id_1, id_2; id_1 = assign_offi_less_level(a1, agenda, day, level_aux, level, found1, depth1); id_2 = assign_offi_less_level(a2, agenda, day, level_aux, level, found2, depth2); if (found1 and found2) { depth1 = depth1 + 1; depth2 = depth2 + 1; if (depth1 <= depth2) { depth = depth1; id = id_1; } else { depth = depth2; id = id_2; } } else if (found1) { depth = depth1 + 1; id = id_1; } else if (found2) { depth = depth2 + 1; id = id_2; } found = found1 or found2; --level_aux; a.plantar(root, a1, a2); } } else found = false; if (found) return id; else return -1; }
void escriure_arbre_int( Arbre<int> &a) { if (not a.es_buit()) { Arbre<int> a1; Arbre<int> a2; int x = a.arrel(); a.fills(a1,a2); escriure_arbre_int(a1); cout << " " << x; escriure_arbre_int(a2); a.plantar(x,a1,a2); } }