all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
29
Task/Visualize-a-tree/Go/visualize-a-tree.go
Normal file
29
Task/Visualize-a-tree/Go/visualize-a-tree.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
Name string
|
||||
Children []*Node
|
||||
}
|
||||
|
||||
func main() {
|
||||
tree := &Node{"root", []*Node{
|
||||
&Node{"a", []*Node{
|
||||
&Node{"d", nil},
|
||||
&Node{"e", []*Node{
|
||||
&Node{"f", nil},
|
||||
}}}},
|
||||
&Node{"b", nil},
|
||||
&Node{"c", nil},
|
||||
}}
|
||||
b, err := json.MarshalIndent(tree, "", " ")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue