Untitled
unknown
c_cpp
a year ago
856 B
8
Indexable
// Online C compiler to run C program online
#include <stdio.h>
#include <stdlib.h>
typedef struct nodo_{
int num;
struct nodo_ *next;
}nodo_t;
nodo_t* inserisciInTesta(nodo_t *l, int num)
{
nodo_t *tmp;
tmp = malloc(sizeof(nodo_t));
if(tmp != NULL)
{
tmp -> num = num;
tmp -> next = l;
l = tmp;
}
else
{
printf("Memoria esaurita");
}
return l;
}
void stampaLista(nodo_t* l)
{
nodo_t *corrente = l;
while(corrente != NULL)
{
printf("%d -> ", corrente->num);
corrente = corrente -> next;
}
printf("NULL\n");
}
int main() {
nodo_t *lista = NULL;
lista = inserisciInTesta(lista, 3);
lista = inserisciInTesta(lista, 5);
lista = inserisciInTesta(lista, 7);
stampaLista(lista);
return 0;
}Editor is loading...
Leave a Comment