Home › Forums › kdb+ › How to walkthrough a tree and calculate value on path? › Re: How to walkthrough a tree and calculate value on path?
-
Try to traverse through Dictionary
tree:([]parent:`A`A`A`B`B`E`E;child:`B`C`D`E`F`G`H;data:(1;2;3;4;5;6;7)); tree:([]parent:`A`A`A`B`B`E`E;child:`B`C`D`E`F`G`H;data:(1;2;3;4;5;6;7)); traverse_dict:exec child!parent from tree; calc:`A`D`C`B`F`E`G`H!1 3 2 1 5 4 6 7; traverse_func:{[st;end;dict;calc] prd calc except[(dict) end;(dict) st] }[;;traverse_dict;calc]; outputTree:([] parent:`A`A`A`A`A`B`B`B`E`E;child:`C`D`F`G`H`F`G`H`G`H); // output update val:traverse_func'[parent;child] from outputTree