更加序列化
func (node *TreeNode) TraverseFunc(f func(*TreeNode)) {

if node == nil {
return
}
node.Left.TraverseFunc(f)
f(node)
node.Right.TraverseFunc(f)

}

func (node *TreeNode) TraverseWithChannel() chan *TreeNode {
out := make(chan *TreeNode)
go func() {
node.TraverseFunc(func(node *TreeNode) {
out <- node
})
close(out)
}()
return out
}


fmt.Println("使用channel遍历二叉树:")
c := root.TraverseWithChannel()
maxNode := 0
for node := range c {
if node.Value > maxNode {
maxNode = node.Value
}
}
fmt.Println("max node value:", maxNode)