Merge a stack with a list

1
struct noPilha{
    float peso;
    int idMala;
    char cor[20];
    struct pessoa donoMala;
    struct noPilha* prox;
};

typedef struct noPilha Elem;

struct noLista{
    struct noPilha mala;
    struct noLista *ant;
    struct noLista *prox;
};

typedef struct noLista NoLista;

void insere_lista(Lista* l, Pilha *pi){

    NoLista* no;

        no = (NoLista*) malloc(sizeof(NoLista));

        no->mala.peso = pi->peso;
        no->prox = NULL;

        if((*l) == NULL){
            no->ant = NULL;
            *l = no;
        }else{
            NoLista* aux = *l;
            while(aux->prox != NULL){
                aux = aux->prox;
            }
            aux->prox = no;
            no->ant = aux;
        }
        nop = no->prox;

}

I have already created the structure to insert the elements into a Stack, now I want to pass that stack by reference and insert the stack elements into a double-chained list, but the way I am doing it it is not inserting stack elements into the list , in that code I just put it to add the weight.

    
asked by anonymous 03.12.2017 / 14:33

1 answer

0

Fixed:

struct noPilha{
    float peso;
    int idMala;
    char cor[20];
    struct pessoa donoMala;

};

typedef struct noPilha Elem;

struct noLista{
    struct noPilha mala;
    struct noLista *ant;
    struct noLista *prox;
}*aux=0;


typedef struct noLista NoLista;


int cont=0;

void insere_lista(Elem mala){


    NoLista* no = (NoLista*)malloc(sizeof(NoLista));

    if(cont == 0)
    {
        no->prox=0;
        no->ant=0;
        no->mala = mala;
        aux =  no;

    }
    else{
        aux->prox = no;
        no->prox=0;
        no->ant=aux;
        no->mala = mala;

    }
    cont++;
}

void exibe(){

    NoLista * no = aux;
    for(int i =0; i<cont; i++)
    {
        if(no == 0) { continue; }
        printf("id %d", no->mala.peso);
        no = no->prox;
    }
}
int main()
{
    Elem mala1;
    mala1.peso = 1.0f;
    insere_lista(mala1);
    mala1.peso = 2.0f;
    insere_lista(mala1);

    exibe();

    return 0;
}

In its insertion function, its error was not having declared any reference, the aux variable always has this out of function (in global scope).

    
03.12.2017 / 16:38