Answer the question
In order to leave comments, you need to log in
How to declare an array of arrays of arbitrary nesting?
I tried
type sl []sl
it compiles, and you can even construct
var foo sl = make(sl, 2)
var bar sl = make(sl, 0)
var bazz sl = make(sl, 2)
bazz[0] = foo
bazz[1] = bar
fmt.Println(bazz)
fmt.Println("size", unsafe.Sizeof(bazz))
Answer the question
In order to leave comments, you need to log in
If you declare type s1 []s1, then fill it like this:
s1 := s1{
{
{}, {
{}, {}, {}, {}, {},
}, {},
},
}
type s1 struct {
Value int // тут любой тип можно, в принципе, лучше указателем
Children []s1
}
func main() {
s1 := s1{
Children: []s1{
{Children: []s1{
{Value: 1}, {Value: 2}, {Value: 3},
}},
{Children: []s1{
{Value: 4}, {Value: 5},
}},
},
}
fmt.Println(s1)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question