Пример #1
0
void Organigrama::leer_arbol(Arbre<int> &a, int marca) {
  int r; 
  cin >> r; 
  if (r != marca) {
      Arbre<int> hi, hd; 
      leer_arbol(hi,marca);
      leer_arbol(hd,marca);
      a.plantar(r,hi,hd);
  }
}
Пример #2
0
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;
}
Пример #3
0
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);
  }
 
}
Пример #4
0
void llegir_arbre_int(Arbre<int>& a, int marca)
//Pre: a es buit
//Post: a conté l'abre llegit de l'entrada
{
  Arbre<int> a1;
  Arbre<int> a2;
  int x;
  cin >> x;
  if (x!= marca) {
    llegir_arbre_int(a1, marca);
    llegir_arbre_int(a2, marca);
    a.plantar(x,a1,a2);
  }
}
Пример #5
0
void Red::leer_red_recursivo(Arbre<int> &a, vector<int> &estaciones, int id_estacion, int tiempo_acumulado) {

  int tiempo = readint();
  if (tiempo >= 0) {

    tiempo_acumulado += tiempo;
    estaciones[id_estacion] = tiempo_acumulado;

    Arbre<int> a1, a2;
    leer_red_recursivo(a1, estaciones, id_estacion * 2 + 1, tiempo_acumulado);

    leer_red_recursivo(a2, estaciones, id_estacion * 2 + 2, tiempo_acumulado);

    a.plantar(tiempo_acumulado, a1, a2);
  }
}