summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-08-05 19:27:35 +0200
committerSanto Cariotti <sancn@live.com>2017-08-05 19:27:35 +0200
commit46139898bccc2268d348fc5744594fac4ea6c34c (patch)
tree69098525b2cbe5a141c815aac6c5a4a2d59af9b8
parent7afdf3d55c7dd8d29bd5e435cc8df2e3ddfcdc03 (diff)
linked-list in Golang
-rw-r--r--go/linkedlist.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/go/linkedlist.go b/go/linkedlist.go
new file mode 100644
index 0000000..7f556e6
--- /dev/null
+++ b/go/linkedlist.go
@@ -0,0 +1,34 @@
+package main
+
+import "fmt"
+
+type node struct {
+ v int
+ next *node
+}
+
+func main() {
+ lista := new(node)
+ lista.next = nil
+
+ lista.carica(5)
+
+ for lista != nil {
+ fmt.Printf("%d ",lista.v)
+ lista = lista.next
+ }
+}
+
+func (head *node) carica(N int) {
+ if N < 1 {
+ return
+ }
+
+ for i := 0; i < N-1; i++ {
+ fmt.Scanf("%d", &head.v)
+ head.next = new(node)
+ head = head.next
+ }
+ fmt.Scanf("%d", &head.v)
+ head.next = nil
+}