#include #include typedef struct noh { int elem; struct noh *prox; } noh; void apaga(noh **inicio) { if (*inicio != NULL) { noh *x = *inicio; // 1 *inicio = (*inicio)->prox; // 2 free(x); // 3 } } void apaga_todos(int k, noh **x) { while (*x != NULL) if ( (*x)->elem == k ) apaga(x); else x = &((*x)->prox); } void insere(int elemento, noh **inicio) { noh *novo = malloc( sizeof(noh) ); // 1 novo->elem = elemento; // 2 novo->prox = *inicio; // 3 *inicio = novo; // 4 } void mostra(noh *x) { printf("[ "); while (x != NULL) { printf("%d ", x->elem); x = x->prox; } printf("] "); } int main() { int num; noh *inicio = NULL; insere(2, &inicio); insere(2, &inicio); insere(1, &inicio); insere(2, &inicio); apaga_todos(2, &inicio); mostra(inicio); return 0; }