Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct nodo *lista;
- typedef struct nodo {
- int val;
- lista next;
- }nodo;
- lista listaVuota (void);
- lista inserTesta(lista L, int el);
- lista cancTesta (lista L);
- lista inserCoda(lista L, int el);
- void stampaLista(lista L);
- lista leggiLista(void);
- int main(void)
- {
- lista L;
- L= leggiLista();
- stampaLista(L);
- return 0;
- }
- lista listaVuota(void)
- {
- return NULL;
- }
- void stampaLista (lista L)
- {
- printf("\nLa lista contiene gli elementi:\n\n");
- while(L!=NULL)
- {
- printf("%d\n",L->val);
- L= L->next;
- }
- printf("\n\n");
- }
- lista cancTesta(lista L)
- {
- lista temp;
- if(L==listaVuota()) return listaVuota();
- temp = L;
- L = L-> next;
- free(temp);
- return L;
- }
- lista inserTesta(lista L,int el)
- {
- nodo *N;
- N = malloc (sizeof(nodo));
- if(N == NULL)
- return L;
- N->val = el;
- N->next = L;
- return N;
- }
- lista leggiLista (void)
- {
- lista L = listaVuota(),prec = L;
- int val;
- while (1)
- {
- printf("\nInserire prossimo valore (0 per terminare):");
- scanf("%d", &val);
- if(val == 0) break;
- temp = inserCoda(L, val);
- if (temp == NULL)
- {
- printf("\n\nMemoria esaurita, inserimento terminato\n\n");
- break;
- }
- L = temp;
- }
- return L;
- }
- lista inserCoda(lista L, int el)
- {
- nodo *N, *temp;
- temp = L;
- if(L == NULL)
- return inserTesta(L,el);
- while (tmp->next != NULL)
- temp= temp->next;
- N=malloc (sizeof(nodo));
- if (N == NULL)
- return NULL;
- N->val = el;
- temp->next = N;
- N->next =NULL;
- return L;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement