#include <stdio.h>
#include <stdlib.h>
typedef struct No {
struct No *prox;
struct No *ant;
char *dado;
} No;
typedef struct Lista {
No* head;
size_t size;
} Lista;
void Remove (Lista* list){
if (list == NULL || list->head == NULL) return; //se vazia nada a fazer senão sair
No* NoARemover = list->head; //guarda um ponteiro para o nó que vai ser removido
list->head = list->head->prox; //faz o head passar a ser o seguinte
free(NoARemover
); //desaloca o antigo head de memoria list->size--; //reajusta o size para o valor correto
}
void imprimeLista(Lista *lista){
if (lista == NULL) return;
printf("\nA imprimir Lista: "); No* head = lista->head;
while (head != NULL){
head = head->prox;
}
}
int main(){
l->head->prox = NULL;
l->head->ant = NULL;
l->head->dado = "teste";
imprimeLista(l);
Remove(l);
imprimeLista(l);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IE5vIHsKICAgIHN0cnVjdCBObyAqcHJveDsKICAgIHN0cnVjdCBObyAqYW50OwogICAgY2hhciAqZGFkbzsKfSBObzsKCnR5cGVkZWYgc3RydWN0IExpc3RhIHsKICAgIE5vKiBoZWFkOwogICAgc2l6ZV90IHNpemU7Cn0gTGlzdGE7CgoKdm9pZCBSZW1vdmUgKExpc3RhKiBsaXN0KXsKICAgICBpZiAobGlzdCA9PSBOVUxMIHx8IGxpc3QtPmhlYWQgPT0gTlVMTCkgcmV0dXJuOyAvL3NlIHZhemlhIG5hZGEgYSBmYXplciBzZW7Do28gc2FpcgoKICAgICBObyogTm9BUmVtb3ZlciA9IGxpc3QtPmhlYWQ7IC8vZ3VhcmRhIHVtIHBvbnRlaXJvIHBhcmEgbyBuw7MgcXVlIHZhaSBzZXIgcmVtb3ZpZG8KICAgICBsaXN0LT5oZWFkID0gbGlzdC0+aGVhZC0+cHJveDsgLy9mYXogbyBoZWFkIHBhc3NhciBhIHNlciBvIHNlZ3VpbnRlCiAgICAgZnJlZShOb0FSZW1vdmVyKTsgLy9kZXNhbG9jYSBvIGFudG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