Exemple #1
0
        public int SumMetadata(Tree.Node node)
        {
            if (node == null)
            {
                return(0);
            }

            return(node.Metadata.Sum() + node.Children.Select(SumMetadata).Sum());
        }
Exemple #2
0
        public int GetValue(Tree.Node node)
        {
            if (node == null)
            {
                return(0);
            }

            if (!node.Children.Any())
            {
                return(node.Metadata.Sum());
            }

            var sum = 0;

            foreach (var m in node.Metadata)
            {
                if (m <= node.Children.Count)
                {
                    sum += GetValue(node.Children[m - 1]);
                }
            }

            return(sum);
        }