summaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
Diffstat (limited to 'go')
-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
+}