Exemplo n.º 1
0
        private BpTreeNode FindNode(BpTreeNode subTreeRoot, int value)
        {
            int index = 0;

            while (index < subTreeRoot.KeysCount && value > subTreeRoot.Keys[index])
            {
                index++;
            }
            if (subTreeRoot.Keys[index] == value)
            {
                if (subTreeRoot.IsLeaf())
                {
                    return(subTreeRoot);
                }
                else
                {
                    return(FindNode(subTreeRoot.Children[index + 1], value));
                }
            }
            if (!subTreeRoot.IsLeaf())
            {
                return(FindNode(subTreeRoot.Children[index], value));
            }
            else
            {
                return(default(BpTreeNode));
            }
        }
Exemplo n.º 2
0
 public BpTreeNode FindNodeToInsertIn(BpTreeNode rootOfTree, int newValue)
 {
     if (rootOfTree.IsLeaf())
     {
         return(rootOfTree);
     }
     for (int i = 0; i < rootOfTree.KeysCount; i++)
     {
         if (newValue < rootOfTree.Keys[i])
         {
             return(FindNodeToInsertIn(rootOfTree.Children[i], newValue));
         }
         if (rootOfTree.KeysCount == i + 1)
         {
             return(FindNodeToInsertIn(rootOfTree.Children[i + 1], newValue));
         }
     }
     return(rootOfTree);
 }