Tags:
create new tag
view all tags
/*
        Lezione Sterbini 28 novembre

        La funzione "aggiungi_elemento" inserisce una struttura "nodo" all'inizio
        di una lista di strutture, mentre "togli_elemento" esegue l'operazione 
        opposta        
*/
#include <stdlib.h>

struct nodo {
   int x
   struct nodo *next;
};

struct nodo *aggiungi_elemento(struct nodo *lista, int val)
{
   struct nodo *nuovo = (struct nodo *) malloc(sizeof(struct nodo));

   nuovo->x = val;
   nuovo->next = lista;

   return nuovo;
}

struct nodo *togli_elemento (struct nodo *lista)
{
    struct nodo *risultato;
   
   if (lista == NULL)
      return NULL;
      
   risultato = lista->next;
   free(lista);

   return risultato;
}

-- ArcangeloTripi - 30 Nov 2002

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2003-10-04 - AndreaSterbini






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback