• Viernes 3 de Mayo de 2024, 02:56

Autor Tema:  Aderir hijo en tercer nivel.  (Leído 923 veces)

jmnenita

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Aderir hijo en tercer nivel.
« en: Domingo 21 de Noviembre de 2010, 20:00 »
0
Hola,
No conosco mucho sobre el tema de arboles binarios. Espero me puedan ayudar. Cree un Arbol usando estructuras que se enlasan por medio de apuntadores entre si. Dependiendo de la informacion que le envie, se creearan los hijos. De la siguiente forma. Tengo un sistem Fotovoltaico el cual puede tener varios Convertidores DC/AC, cada convertidor puede tener una o varias entradas de DC. Cada entrada DC puede tener uno o varios Mosulos solares. No conozco la cantidad de cada uno de estos elemetos. Da acuerdo a la informacion que sea ingresada "where" se crearan cada uno de estos nos pdres/hijos. la informacion de cada elemto la estoy guardando en estructuras y cada estructura tiene su correspondiente apuntadores a la estructura anterior o estructura siguiente. El problema que tengo es el siguiente:  no se como decir al hijo que se encuentra en tercer nivel que tiene un nuevo elemento hijo. En el programa lo coloque como XXX por que no se como hacer referencia a este.
Espero me puedan ayudar.
En el software solo defini un apuntador global: photovoltaik_t *myPV que apunta a la raiz y de ahi tengo que llegar hasta el final de cada rama

Muchas gracias por su ayuda y colaboracion
Código: C
  1.  
  2. photovoltaik_t *myPV
  3.  
  4.  
  5. if(mode != 0) {
  6.      if (what==0) {
  7.  
  8.         myPV->name = (char*) malloc(sizeof(char) * (strlen(namepv)+1));
  9.       strcpy(myPV->name, namepv);
  10.       myPV->pi_count = maxPIpv;
  11.       }
  12.      if(what == 1) {
  13.         powerinverter_t *pi = pi_createPowerInverter();
  14.          pi->name = (char*) malloc(sizeof(char) * (strlen(namepi)+1));
  15.          strcpy(pi->name, namepi);
  16.          pi->serie = (char*) malloc(sizeof(char) * (strlen(seriepi)+1));
  17.          strcpy(pi->serie, seriepi);
  18.          pi->U_mpp_min= minVpi;
  19.          pi->U_mpp_max=maxVpi;
  20.          pi->I_max = maxIpi;
  21.          pi->P_max = maxPpi;
  22.          pi->mpps_count = maxMpppi;
  23.          temp= pv_addPowerinverter(myPV, pi);
  24.          printf("temp: %d ", temp);
  25.       }
  26.         if(what == 2) {
  27.          mpp_t *mpp = mpp_createMPP();
  28.          mpp->name = (char*) malloc(sizeof(char) * (strlen(namempp)+1));
  29.          strcpy(mpp->name, namempp);
  30.          mpp->U_Mpp_Min = minVmpp;
  31.          mpp->U_Mpp_Max = maxVmpp;
  32.          mpp->I_Mpp_Max = maxImpp;
  33.          mpp->strings_max = maxMSmpp;
  34.  
  35.          pi_addMPP(myPV->pi[where],mpp);
  36.  
  37.         }
  38.          if(what == 3) {
  39.          modulestring_t *ms = ms_createModuleString();
  40.          ms->name = (char*) malloc(sizeof(char) * (strlen(namems)+1));
  41.          strcpy(ms->name, namems);
  42.          ms->ms_count = maxMDms;
  43.         mpp_addModuleString(XXXXX,ms);
  44.       }
  45.         if(what == 4){
  46.          module_t *m = m_createModule();
  47.          m->name = (char*) malloc(sizeof(char) * (strlen(namemd)+1));
  48.          strcpy(m->name, namemd);
  49.          m->serie = (char*) malloc(sizeof(char) * (strlen(seriemd)+1));
  50.          strcpy(m->name, seriemd);
  51.          m->U_max_sys = maxVsysmd;
  52.          m->U_ms_max  = maxVmd;
  53.          m->I_ms_max  = maxImd;
  54.          m->P_max = maxPmd;
  55.          m->short_circuit = maxSCmd;
  56.          m->U_leer = scImd;
  57.          m->efficiency_factor = offactmd;
  58.          ms_addModule(XXX,m);
  59.        }
  60.      }
  61.  
  62.