From 46139898bccc2268d348fc5744594fac4ea6c34c Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 5 Aug 2017 19:27:35 +0200 Subject: linked-list in Golang --- go/linkedlist.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 go/linkedlist.go 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 +} -- cgit v1.2.3-18-g5258