0
I am doing a function to remove ALL even elements from a simply chained list, but when I run the system, only one even element is removed each time I call the function. Ex: Elements={2, 4, 5, 3}, if I call the function, it erases element 4, and after I call again, erases 2. Does anyone know how to make this function erase all elements even at once?
int remover_pares(struct no **c){
struct no *p, *q;
if(*c==NULL){
printf("LISTA VAZIA");
return 0;
}
else{
p=*c;
q=*c;
for(p=*c;p!=NULL;p=p->prox){
if(p->dado%2==0){
if(p==*c){
*c=(*c)->prox;
free(p);
return 1;
}else{
q->prox=p->prox;
free(p);
return 1;
}
}
}
}
}
You quit the job
return 1
Whenever you find an even element, this way it doesn’t go through your list, and you need to call it again as it already does. I don’t know if there’s a need forreturn 1
.– gato
I see.... Yes, thank you very much!
– Sbim