summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-03-19 21:38:16 +0100
committerGitHub <noreply@github.com>2017-03-19 21:38:16 +0100
commit785a4d0a00df64be60a4c3e81a11ea9f9ec32b4f (patch)
treef9272da782784527df95898e36199a83b0fcfa22
parenteff9b7e3ac6f894e03d644bfba564909a260794c (diff)
Create esempioLista.cc
-rw-r--r--esempioLista.cc54
1 files changed, 54 insertions, 0 deletions
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 <iostream>
+
+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;
+}