hello,
l fixed the problem by adding a function called data_node() as follows :
function data_node(node)
println("data : ", node.data)
println("index ", node.index)
end
for i in 1:nChildren
for k in 1:root.child[i].nchild
data_node(root.child[i].child[k])
end
end
On Monday, July 4, 2016 at 4:39:54 PM UTC+2, Ahmed Mazari wrote:
>
> The idea that comes to my mind is the following :
> add a new variable to MyNode type wich is index,
> type MyNode{T}
> data::Vector{T}
> level::Int
> child :: Vector{MyNode}
> nchild :: Int
> index :: Int
> end
>
> function node_info(node)
> println("Level : ", node.level)
> println("nChildren: ", node.nchild)
> println("data : ", node.data)
> println("index ", node.index)
> end
>
> # set an empty list to store the leafs of each child
> for i in 1:nChildren
> list_leafs_of_child[i]= Int64[] # for instance list_leafs_of_child[1] =
> [2, 5,4,9 ..]
> end
>
> for i in 1:nChildren
> for j in 1:nGrandChildren
> if contains(grand_children_list[i], j) # check whether j is contained
> in grand_children_list[i] if so add j to the list of leafs of child[i]
> # contains is a function in julia
> list_leafs_of_child[i]= [list_leafs_of_child j] # add j to the list
> , j : new element , list_leafs_of_child : the ancient list
> end
> end
>
> but it's not working my function is not well my loop is not well defined.
> sorry for these stupid questions. l'm a dummy in julia hope that l don't
> bother you
>
>
>
>
> On Monday, July 4, 2016 at 2:09:25 PM UTC+2, Andre Bieler wrote:
>>
>> Well for 1) this is pretty much exactly what is being done in my example
>> code.
>> The difference is that it prints out the content of "data". (But I put
>> the index of
>> each child into that "data" varialbe)
>>
>> My suggestion is that you insert a new field in the MyNode type, this
>> variable
>> can then hold an index. E. g. for child1 this index is 1, etc.
>>
>> Then do the same thing my example does in the end, but print out this
>> index instead
>> of data.
>> I think you should try implementing this on you own, it will probably
>> help you understand
>> what is going on in the code. If you have problems doing so you can come
>> back with more
>> questions.
>>
>> Cheers,
>> Andre
>>
>