예제 #1
0
        /// <summary>
        /// Search through the current tree and return the first
        /// node without a complete set of children.  The arc
        /// number for the first missing child is returned in
        /// position 0 of the arcNum array.
        /// </summary>
        /// <param name="node">The node at which to begin the search.</param>
        /// <param name="arcNum">An integer array of size 1.  The arc
        /// number for the first missing child is
        /// returned in arcNum[0].</param>
        /// <returns>A reference to the first incomplete node
        /// in the tree (farthest left).  The method
        /// returns null if the tree is already complete,
        /// or if the tree is empty.</returns>
        public DecisionTreeNode findIncompleteNode(DecisionTreeNode node, int[] arcNum)
        {
            // The search is recursive - at some point, we
            // may want to change this to a non-recursive
            // algorithm (if we start dealing with extremely
            // large trees?)

            // Base cases.
            if (node == null || node.isLeaf())
            {
                return(null);
            }

            // Recursive case. This node is not a leaf - so descend.
            for (int i = 0; i < node.getArcLabelCount(); i++)
            {
                DecisionTreeNode nextNode;

                if ((nextNode = findIncompleteNode(node.getChild(i), arcNum)) != null)
                {
                    return(nextNode);
                }
            }

            if ((arcNum[0] = node.getFirstMissingChild()) >= 0)
            {
                // We found a node with a missing child, which
                // is already stored in arcNum - so return this
                // node.
                return(node);
            }

            // We searched all the subtrees attached to this
            // node, and didn't find anything, so return null.
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Search through the current tree and return the first
        /// node without a complete set of children.  The arc
        /// number for the first missing child is returned in
        /// position 0 of the arcNum array.
        /// </summary>
        /// <param name="node">The node at which to begin the search.</param>
        /// <param name="arcNum">An integer array of size 1.  The arc
        /// number for the first missing child is
        /// returned in arcNum[0].</param>
        /// <returns>A reference to the first incomplete node
        /// in the tree (farthest left).  The method
        /// returns null if the tree is already complete,
        /// or if the tree is empty.</returns>
        public DecisionTreeNode findIncompleteNode(DecisionTreeNode node, int[] arcNum)
        {
            // The search is recursive - at some point, we
            // may want to change this to a non-recursive
            // algorithm (if we start dealing with extremely
            // large trees?)

            // Base cases.
            if (node == null || node.isLeaf())
            {
                return null;
            }

            // Recursive case. This node is not a leaf - so descend.
            for (int i = 0; i < node.getArcLabelCount(); i++)
            {
                DecisionTreeNode nextNode;

                if ((nextNode = findIncompleteNode(node.getChild(i), arcNum)) != null)
                {
                    return nextNode;
                }
            }

            if ((arcNum[0] = node.getFirstMissingChild()) >= 0)
            {
                // We found a node with a missing child, which
                // is already stored in arcNum - so return this
                // node.
                return node;
            }

            // We searched all the subtrees attached to this
            // node, and didn't find anything, so return null.
            return null;
        }