1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package main import "fmt" type treeNode struct { value int left, right *treeNode } func main() { var tree treeNode fmt.Println(tree) } ===================================output=================================== {0 <nil> <nil>} ===================================output===================================
package main import "fmt" type treeNode struct { value int left, right *treeNode } func main() { var root treeNode
root = treeNode{value: 3} root.left = &treeNode{} root.right = &treeNode{5, nil, nil} root.right.left = new(treeNode)
nodes := []treeNode { {value: 3}, {}, {6, nil, &root}, }
fmt.Println(nodes) } ===================================output=================================== [{3 <nil> <nil>} {0 <nil> <nil>} {6 <nil> 0xc420098020}] ===================================output=================================== 不论地址还是结构本身,一律使用.来访问成员
|