Insert sub-list C

Asked

Viewed 426 times

1

Hello, I’m having a hard time working with chained sublists.

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

I have declared 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 that form correct? How could I insert a list of houses within a list of streets and a list of streets within a list of neighborhoods.

1 answer

1


How could I 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 [how could I do to insert] a list of streets within a list of neighborhoods

In the same way as above, but with other structures.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.