I'm making a function to remove ALL pairs from a list that is simply chained, but when I run the system, only one element is removed each time I call the function. Ex: Elements = {2, 4, 5, 3}, if I call the function, it deletes element 4, and after I call again, it clears 2. Does anyone know how to do this function delete all even elements 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;
}
}
}
}
}