gccruzado
BAN USER- 0of 0 votes
AnswersDefining a tree as such that the parent node always contains the sum of children nodes.
- gccruzado in Spain
Coul be something like this):
private static int p_get_nodes_value_sum(TreeNodeCollection v_tree_original)
{
//TreeNodeCollection a_child = v_tree_original.ChildNodes;
//TODO:sum the child nodes
int a_suma = 0;
foreach (TreeNode a_child in v_tree_original)
{
if (a_child.ChildNodes.Count > 0)
a_suma += p_get_nodes_value_sum(a_child.ChildNodes);
else
a_suma += Convert.ToInt16(a_child.Value);
}
return a_suma;
}
public class TreeParentSum: TreeNode{
public TreeParentSum(TreeNode v_tree)
{
int a_sum = p_get_nodes_value_sum(v_tree.ChildNodes);
TreeNode a_node = new TreeNode("PARENTNODE", a_sum.ToString());
a_node.ChildNodes.Add(v_tree);
}
}| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer