3
I have this little problem of removing an element from the beginning of a list, even doing the schematic in the drawing I could not. The strange thing is that it works with up to 3 elements, from 4 cmd (which I’m using gcc to compile) to answer. Any idea?
typedef struct evento_t {
double tempo;
char descricao[50];
int id_origem, id_destino;
struct evento_t *prox;
} evento_t;
void eventos_remover_inicio (evento_t **lista) {
evento_t *auxiliar = *lista;
if (*lista == NULL)
printf ("Lista vazia\n");
else
*lista = auxiliar->prox;
free(auxiliar);
}
The only "wrong" thing I’m seeing is that after checking if the list is empty, you still let it be realized
free
in the empty list:free(auxiliar) => free(NULL)
if*lista == NULL
. Even so, if the environment follows the pattern, this should not generate side effects ("If ptr is NULL, no Operation is performed"). You need to show the code that declares and initializes a list and removes the elements.– pepper_chico