Insert sublist into list C

1

Hello, I'm having trouble working with linked sublists.

I would like to know the correct way to insert a sublist into a list.

I declare the lists as follows:

struct Casa
{
   int id_consumidor;
   int casa;
   float consumo;
   char *nome_consumidor;
   struct Casa *proxc;
}

typedef struct Casa house;

struct Rua
{
    int id_rua;
    char *nome_rua;
    house *head_casa;
    struct Rua *proxr;

}

typedef struct Rua street;

struct Bairro
{
int id_bairro;
char *nome_bairro;
street *head_rua;
struct Bairro *proxb;
}

typedef struct Bairro nhood;

Is this form correct? How could I do to insert a list of houses within a list of streets and a list of streets within a list of neighborhoods.

    
asked by anonymous 19.04.2015 / 17:12

1 answer

1
  

How could I do to insert a list of houses within a list of streets

struct Casa *lista_de_casas = NULL;
struct Rua *exemplo1;
exemplo1 = calloc(1, sizeof *exemplo1); // nao esquecer de fazer #include <stdlib.h>
if (exemplo1 == NULL) /* erro */;
exemplo1->head_casa = lista_de_casas; // insere lista vazia
free(exemplo1);
  

and [as I could do to insert] a list of streets within a neighborhood list

As above, but with other structures.

    
19.04.2015 / 17:56