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?
– Fábio Morais
that. I started working with queue recently then I’m having some difficulties
– Igor Vargas
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
– Fábio Morais
Which one? You have already created an empty list, you have already entered values and you have shown even elements.
– Fábio Morais
I think it’s to make a list and be accepted only even numbers.
– Igor Vargas
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.
– Fábio Morais
But it’s not working it doesn’t just show the pairs, it’s showing the whole list.
– Igor Vargas
He’s just showing his pairs,
10
,20
and30
are even numbers.... What did you want to happen? In this case you only entered even numbers– Fábio Morais
I was confusing the number 30 vlw by the help
– Igor Vargas
If you have any questions about the linked lists I can give a good implementation for this
– Fábio Morais