Exemplo n.º 1
0
        /// <summary>
        /// Returns the number of nodes contained in the tree.
        /// </summary>
        /// <returns>The number of nodes contained in the tree.</returns>
        public static int GetSize(this TreeEntityBase treeEntity)
        {
            if (treeEntity is null)
            {
                throw new ArgumentNullException(nameof(treeEntity));
            }

            return(TreeEntityExtensions.GetSubtreeSize(treeEntity.RootNode));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the number of nodes contained in the subtree of the given <paramref name="node"/>.
        /// </summary>
        private static int GetSubtreeSize(TreeNode?node)
        {
            if (node is null)
            {
                return(0);
            }

            int sum = 1; // Includes the node passed in.

            for (int i = 0; i < node.ChildNodes.Count; i++)
            {
                sum += TreeEntityExtensions.GetSubtreeSize(node.ChildNodes[i]);
            }

            return(sum);
        }