Exemple #1
0
        //--------------------------------------------------------------
        //this method will delete a key value from the leaf node it is |
        //in.  We will use the search method to traverse through the   |
        //tree to find the node where the key is in.  We will then     |
        //iterated through key[] array until we get to node and will   |
        //assign k[i] = k[i+1] overwriting key we want to delete and   |
        //keeping blank spots out as well.  Note that this is the most |
        //simple case of delete that there is and we will not have time|
        //to implement all cases properly.                             |
        //--------------------------------------------------------------

        public void deleteKey(BTreeV2 <T> t, T key)
        {
            BtreeNodeV2 <T> temp = new BtreeNodeV2 <T>(Degree, null); //temp Bnode

            temp = search(t.root, key);                               //call of search method on tree for key

            if (temp.leaf && temp.NumberKeyInNode > Degree - 1)
            {
                int i = 0;

                while (key.CompareTo(temp.getValue(i)) > 0)
                {
                    i++;
                }
                for (int j = i; j < 2 * Degree - 2; j++)
                {
                    temp.key[j] = temp.getValue(j + 1);
                }
                temp.NumberKeyInNode--;
            }
            else
            {
                Console.WriteLine("This node is either not a leaf or has less than order - 1 keys.");
            }
        }
Exemple #2
0
        //--------------------------------------------------------------
        //this will be the method to insert in general, it will call    |
        //insert non full if needed.                                    |
        //--------------------------------------------------------------

        /// <summary>
        /// Insére une clé dans un arbre
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="key"></param>
        public void insert(BTreeV2 <T> tree, T key)
        {
            BtreeNodeV2 <T> r = tree.root;//this method finds the node to be inserted as

            //it goes through this starting at root node.
            if (r.NumberKeyInNode == 2 * Degree - 1)                   //if is full
            {
                BtreeNodeV2 <T> s = new BtreeNodeV2 <T>(Degree, null); //new node

                tree.root = s;                                         //\
                                                                       // \
                s.leaf = false;                                        //  \
                                                                       //   > this is to initialize node.
                s.NumberKeyInNode = 0;                                 //  /
                                                                       // /
                s.child[0] = r;                                        ///

                split(s, 0, r);                                        //split root

                nonfullInsert(s, key);                                 //call insert method
            }
            else
            {
                nonfullInsert(r, key);//if its not full just insert it
            }
        }
Exemple #3
0
        /// <summary>
        /// Affiche le noeud trouvé dans l'arbre si la clé existe
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="key"></param>
        public void SearchPrintNode(BTreeV2 <T> tree, T key)
        {
            BtreeNodeV2 <T> temp = new BtreeNodeV2 <T>(Degree, null);

            temp = search(tree.root, key);

            if (temp == null)
            {
                Console.WriteLine("The Key does not exist in this tree");
            }
            else
            {
                print(temp);
            }
        }