With show even items in a C list

Asked

Viewed 154 times

1

I have a question in this exercise. I tried several ways but I do not know how to take the position of the pointer to use the content in this case.

• Describe steps for creating a new element in the list? Develop an algorithm to create an empty chained list. Then create a function that allows you to insert elements into it. Finally, display the even values of the list

#include <stdio.h>
#include <stdlib.h>

typedef struct Lista
{
    int dado;
    struct Lista *prox;

} lista;

lista *insere (lista *prox, int dadoEnviado)
{
    lista *novo;
    novo = (lista *)malloc(sizeof(lista));
    novo->dado = dadoEnviado;
    novo->prox = prox;
    return novo;
}

/*void imprime(lista *pont){

    lista *p;
    for( p = pont; p!=NULL; p=p->prox){
            printf("%d --",p->dado);
    //}

}*/

void imprimePar(lista *l)
{
    lista *p;
    for( p = l; p!=NULL; p=p->prox)
    {
        if( p->dado % 2 == 0)
        {
            printf("%d",p->dado);
        }
    }
}

main()
{
    lista *pont;
    pont = NULL;
    pont = insere(pont, 10);
    pont = insere(pont, 20);
    pont = insere(pont, 30);
    //imprime(pont);
    imprimePar(pont);
}
  • What do you mean? You want to take the top of the queue?

  • that. I started working with queue recently then I’m having some difficulties

  • To do that, you’d have to rewrite the entire list code. The program you have put works well, if you want I can answer with a linked list in which it is possible to do what you want, to get the start/ end of the list

  • Which one? You have already created an empty list, you have already entered values and you have shown even elements.

  • I think it’s to make a list and be accepted only even numbers.

  • This question is very confusing, edit the question clearly and tell us what the real problem is so we can help. Because what you mentioned already did in that code.

  • But it’s not working it doesn’t just show the pairs, it’s showing the whole list.

  • He’s just showing his pairs, 10, 20 and 30 are even numbers.... What did you want to happen? In this case you only entered even numbers

  • 1

    I was confusing the number 30 vlw by the help

  • If you have any questions about the linked lists I can give a good implementation for this

Show 5 more comments
No answers

Browser other questions tagged

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