From 785a4d0a00df64be60a4c3e81a11ea9f9ec32b4f Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 19 Mar 2017 21:38:16 +0100 Subject: Create esempioLista.cc --- esempioLista.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 esempioLista.cc diff --git a/esempioLista.cc b/esempioLista.cc new file mode 100644 index 0000000..b1e47c1 --- /dev/null +++ b/esempioLista.cc @@ -0,0 +1,54 @@ +#include + +using namespace std; + +struct node +{ + int x; + node* link; +} node; + +struct node *crea(int N, struct node *p); + +int main() +{ + struct node *lista = NULL; + + lista = crea(3, lista); + + while(lista != NULL) + { + cout << "val -> " << lista->x << endl; + lista = lista->link; + } + return 0; +} + +struct node *crea(int N, struct node *p) +{ + struct node *punt; + p = new struct node; + + if(N == 1) { + cout << "Numero: "; + cin >> p->x; + + punt = p; + p->link = NULL; + } else if(N > 1){ + cout << "Numero: "; + cin >> p->x; + + punt = p; + for(int i = 2; i <= N; i++) + { + punt->link = new struct node; + punt = punt->link; + cout << "Numero: "; + cin >> punt->x; + } + punt->link = NULL; + } + + return p; +} -- cgit v1.2.3-18-g5258