I'm programming a headless threaded list, in this program there is a remove function that aims to delete all repeated integers in a list, px: by taking the values 8 2 8 3 8 the function has to return 2 3, however this function apparently looped because the execution does not end, not appearing runtime and not errors or warnings in compilation. follow code:
#include<stdio.h>
#include<stdlib.h>
struct reg {
int conteudo;
struct reg *prox;
};
typedef struct reg celula;
void insere (celula **p, int x) {
celula *novo, *q;
q = *p;
novo = (celula *)malloc(sizeof(celula));
novo->conteudo = x;
if (*p == NULL) {
novo->prox = NULL;
*p = novo;
}
else {
while (q->prox != NULL)
q = q->prox;
novo->prox = q->prox;
q->prox = novo;
}
}
celula* Remove (celula *p, int x) {
celula *aq, *q, *aux;
aq = NULL;
aux = q = p;
while (aux != NULL) {
while (q->prox != NULL && q->conteudo != x) {
aq = q;
q = q->prox;
}
if (aq == NULL) p = q->prox;
else aq->prox = q->prox;
free(q);
aux = aux->prox;
}
return q;
}
void imprime (celula *p) {
celula *q;
if (p == NULL) printf ("Lista Vazia");
for (q = p; q != NULL; q = q->prox)
printf ("%d ", q->conteudo);
printf("\n");
}
int main() {
celula *lista = NULL;
celula *lst = NULL;
insere(&lista, 8);
insere(&lista, 2);
insere(&lista, 8);
insere(&lista, 3);
insere(&lista, 8);
imprime(lista);
lst = Remove(lista, 8);
imprime(lst);
return 0;
}