Linked list, union of structures

3

I'm having a hard time joining two structures in the same linked list, I've never worked with generic lists or even linked two structures together in one activity, I have the following structures:

struct Patio {
    char iden_patio;
    int capacidade;
    struct Patio *prox;
};  

typedef struct Patio patio;

struct Rec_Emp {    
    char nome_rec[10];
    char ident_rec[10];
    int uso_rec;
    int taxa_rec;
    struct Rec_Emp *prox;
};    

typedef struct Rec_Emp recuperadora;

I wanted to associate these two lists without necessarily joining all the variables, more or less so, for each patio, associate the recovery elements, eg: iden_patio: A, capacity: 10000, rec_name: Rec01, use_rec: 0, etc. .. As I said I could even join the two, form a bigger struct, but I would like a more elegant solution, because I wanted to preserve the identities of the patios and recuperadoras, thank you for attention right now.     

asked by anonymous 30.03.2017 / 03:29

1 answer

2

With the information I have about your problem, I can give you two answers.

Taking into account that you need to know which reclaimers are associated with a patio, I recommend doing so:

#define RECS_PATIO 2

struct Rec_Emp {
    char nome_rec[10];
    char ident_rec[10];
    int uso_rec;
    int taxa_rec;
    struct Rec_Emp *prox;
};

typedef struct Rec_Emp recuperadora;

struct Patio {
    char iden_patio;
    int capacidade;
    struct Patio *prox;
    struct Rec_Emp *lista[RECS_PATIO];
}; 

typedef struct Patio patio;

Using the above structures, let's suppose you want to associate a recuperator with a yard p and then print out some of the recuperator by going through the yard. Here's how:

p.lista[0] = &r;
int resp = 0;
resp = p.lista[0]->uso_rec; // Acessando uso_rec da recuperadora pela variável do pátio

Taking into account that you need to know which patio is associated with a recuperator, I recommend doing so:

struct Patio {
    char iden_patio;
    int capacidade;
    struct Patio *prox;
}; 

typedef struct Patio patio;

struct Rec_Emp {
    char nome_rec[10];
    char ident_rec[10];
    int uso_rec;
    int taxa_rec;
    struct Rec_Emp *prox;
    struct Patio *p;
};

typedef struct Rec_Emp recuperadora;

Using the code above, let's suppose you want to associate a patio with a reclaimer and then print some patio value by accessing the reclaimer. Here's how:

r.p = &p;
int resp = 0;
resp = r.p->capacidade;

I hope you have remedied your doubts, anything is available.

Reference: My knowledge in AED's.

    
30.03.2017 / 05:22