mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:21:38 +08:00
fix: coding style and file format for all example.
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
// node_structures.go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Node struct {
|
||||
le *Node
|
||||
data interface{}
|
||||
ri *Node
|
||||
}
|
||||
|
||||
func NewNode(left, right *Node) *Node {
|
||||
return &Node{left, nil, right}
|
||||
}
|
||||
|
||||
func (n *Node) SetData(data interface{}) {
|
||||
n.data = data
|
||||
}
|
||||
|
||||
func main() {
|
||||
root := NewNode(nil,nil)
|
||||
root.SetData("root node")
|
||||
// make child (leaf) nodes:
|
||||
a := NewNode(nil,nil)
|
||||
a.SetData("left node")
|
||||
b := NewNode(nil,nil)
|
||||
b.SetData("right node")
|
||||
root.le = a
|
||||
root.ri = b
|
||||
fmt.Printf("%v\n", root) // Output: &{0x125275f0 root node 0x125275e0}
|
||||
}
|
||||
// node_structures.go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Node struct {
|
||||
le *Node
|
||||
data interface{}
|
||||
ri *Node
|
||||
}
|
||||
|
||||
func NewNode(left, right *Node) *Node {
|
||||
return &Node{left, nil, right}
|
||||
}
|
||||
|
||||
func (n *Node) SetData(data interface{}) {
|
||||
n.data = data
|
||||
}
|
||||
|
||||
func main() {
|
||||
root := NewNode(nil, nil)
|
||||
root.SetData("root node")
|
||||
// make child (leaf) nodes:
|
||||
a := NewNode(nil, nil)
|
||||
a.SetData("left node")
|
||||
b := NewNode(nil, nil)
|
||||
b.SetData("right node")
|
||||
root.le = a
|
||||
root.ri = b
|
||||
fmt.Printf("%v\n", root) // Output: &{0x125275f0 root node 0x125275e0}
|
||||
}
|
||||
|
Reference in New Issue
Block a user