Studying example from https://blog.golang.org/maps on maps(code is below)
Questions I have
1)I don’t understand the struct Node… How can Next be pointed to itself?
2)How would you initialize this struct with data?? I can’t even run to exam how this works…
Any help would be appreciated. thank you!
package main
import "fmt"
func main() {
type Node struct {
Next *Node
Value interface{}
}
var first *Node
visited := make(map[*Node]bool)
for n := first; n != nil; n = n.Next {
if visited[n] {
fmt.Println("cycle detected")
break
}
visited[n] = true
fmt.Println("nada")
fmt.Println(n.Value)
}
}