简体   繁体   中英

Dealing with linkedlist in c

i've a header declared like this

#include <stdlib.h>

struct Nodo {
    struct Nodo *pAnterior;
    struct Nodo *pProximo;
    CACHORRO cachorro;
};

typedef struct Nodo *Lista;
typedef struct Nodo *DoenteMachucado;
typedef struct Nodo *portePequeno;
typedef struct Nodo *porteMedio;
typedef struct Nodo *porteGrande;

But when i try to use the function

void inserir(Lista *lista, CACHORRO elem)
{
    Lista Nodo;
    Nodo = (Lista)malloc(sizeof(struct Nodo));
    if(Nodo == NULL)
        printf("Sem memoria\n");

    Nodo->cachorro = elem;
    Nodo->pAnterior = NULL;
    Nodo->pProximo = (*lista);

    if((*lista) != NULL)
        (*lista)->pAnterior = Nodo;

    (*lista) = Nodo;
}

like this

inserir(DoenteMachucado, elem);

it doesnt work, i am declaring a elem CACHORRO

  void inserir(Lista *lista, CACHORRO elem)

The above statement reduces to

  void inserir(struct Nodo **lista, CACHORRO elem)//1

and you call the above function as

  DoenteMachucado something; 
  inserir(something, elem); //remember DoenteMachucado is a type not a variable ,something is a variable.so i have changed this.

where the first argument is of type struct Nodo*

  inserir(struct Nodo* something, elem);//2

the parameters don't match at 1 and 2. you might want to call the function as

 DoenteMachucado something;
 inserir(&something, elem);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM