1) yes they are of the same type as root and child . the leaf is the last
level of the tree so it doesn't have any child
2) yes no children with zero leaf at least one leaf

On Fri, Jul 1, 2016 at 4:37 PM, Andre Bieler <[email protected]>
wrote:

> I think I start seeing what you want. A few questions:
>
> 1) Can the leafs be of the same type as the root and child?
> 2) Does every child need to have one child at least? (= no child with zero
> leafs)
>
> you can do the following:
>
> ```julia
>
> # this generates a list of empty vectors that can hold MyNode types, each
> of these vectors
> # will then be filled with leafs
> # once all vectors are filled with leafs we can distribute them to the
> children
>
> all_leafs = Any[MyNode[] for i in 1:nChildren]
>
> for i in 1:100
>   childIndex = rand(1:nChildren) # pick to which child this leaf will go
>   #create your leaf here with necessary stuff like above
>   leaf=MyNode(data,level, MyNode[], 0)
>   push!(all_leafs[childIndex], leaf)
> end
> ```
>
> then you can distribute those leafs:
>
> ```julia
>
> for i in 1:nChildren
>   root.child[i].child = all_leafs[i]
> end
> ```
>

Reply via email to