The tree struct is below:
type TreeData struct {
Name string `json:"name"`
Depth int `json:"depth"`
Children []TreeData `json:"children"`
}
I have two trees, and I want merge them into one tree.
How can I do that?
If someone could show me your code, I would be very appreciate!!
I wonder if I could use the recursion way to finish the merge?
treeone:
{
"name": ".",
"depth": 1,
"children": [
{
"name": "com",
"depth": 2,
"children": [
{
"name": "didi"
"depth": 3,
"children": [
{
"name": "dev",
"depth": 4,
"children": null
}
]
}
]
}
]
}
treetwo:
{
"name": ".",
"depth": 1,
"children": [
{
"name": "com",
"depth": 2,
"children": [
{
"name": "didi"
"depth": 3,
"children": [
{
"name": "influxdb",
"depth": 4,
"children": [
{
"name": "cluster-one"
"depth": 5
"children": null
}
]
}
]
}
]
}
]
}
merge:
{
"name": ".",
"depth": 1,
"children": [
{
"name": "com",
"depth": 2,
"children": [
{
"name": "didi"
"depth": 3,
"children": [
{
"name": "influxdb",
"depth": 4,
"children": [
{
"name": "cluster-one"
"depth": 5
"children": null
}
]
},
{
"name": "dev",
"depth": 4,
"children": null
}
]
}
]
}
]
}