What is the operation of a list chained in C? [duplicate]

0

I'm doing a job for college and have not yet fully understood the logic behind a list chained to C.

I need to register login, name and value in a record, from which I created a struct (set of variables); I created another struct to be my nodes and a third struct to be the lita chained.

How do these three structs relate to each other and why do they all have pointers to next? Would not it only be necessary for nodes to have pointers for the next?

There is a difference from traditional examples. In this example, why does the struct record have pointer? Would not the struct node's pointers suffice?

typedef struct registro_st{         // sequência de objetos do mesmo tipo
        char login[50];
        char nome[50];
        float valor;
        struct registro *prox;
    } registro;


typedef struct nodo_st{
    registro dado;
    struct nodo *prox;
} nodo;


typedef struct Lista_st{
    nodo *cabeca;
    nodo *cauda;
    int tamanho;
} lista;
    
asked by anonymous 21.07.2017 / 23:05

1 answer

1

I am not an expert, but for me there are unnecessary things there, I think you could simplify for this type:

typedef struct registro_st{
    char login[50];
    char nome[50];
    float valor;
    struct registro *prox;
} registro;

typedef struct Lista_st{
    registro *cabeca;
    registro *cauda;
    int tamanho;
} lista;

On the linked list, basically every "object" in the list will point to the next element in the list, if any. "It's just chained up." If it is doubly chained, each "object" instead of just pointing to the next, will also point to the previous one.

And in the case of your code, you will have the pointers at the beginning and end of the list. (head and tail)

I hope to have helped something!

    
21.07.2017 / 23:17