codice:int add_first(list *l, void *el) { /* inserisce l'elemento el in testa alla lista l */ if (!el) return OP_NO_ATTRIBUTE_ERROR; list t; t=malloc(sizeof(struct NodoLista)); if (!t) return OP_MEM_ERROR; t->value=el; t->next=*l; *l=t; return OP_OK; } int add_last(list *l, void *el) { /* inserisce l'elemento el in coda alla lista l */ if (!el) return OP_NO_ATTRIBUTE_ERROR; list t; if (*l == NULL) { // lista vuota *l=malloc(sizeof(struct NodoLista)); (*l)->value=el; (*l)->next=NULL; return OP_OK; } t = *l; // c'è almeno 1 el while (t->next != NULL) t = t->next; t->next=malloc(sizeof(struct NodoLista)); if (!t) return OP_MEM_ERROR; t=t->next; t->value=el; t->next=NULL; return OP_OK; }

Rispondi quotando