// L-35 MCS 360 Fri 12 Nov 2010 : mcs360_btree.h

/* This file defines a B-tree. */

#ifndef MCS360_BTREE_H
#define MCS360_BTREE_H
#define NULL 0

namespace mcs360_btree
{
   template<typename Item_Type, int numbchil>
   class B_Tree
   {
      private:

         #include "mcs360_btree_node.h"

         Node *root;  // data member

         int binary_search
            (int first, int last, Item_Type i);
         // Applies binary search to find i in the array
         // starting at first and ending at last.
         // The index on return is either where i occurs,
         // or the child where i should be inserted.

      public:

         B_Tree();

         B_Tree(int n, Item_Type *a);
         // creates a tree with n items in a
         // precondition: n < numbchil
         
         B_Tree(int n, Item_Type *a,
                B_Tree<Item_Type,numbchil> *c);
         // creates a tree with n items in a
         // and n+1 children in c
         // precondition: n < numbchil
         
         int get_size();
         // returns number of items at root of tree

         Item_Type *get_data();
         // returns the data at the root of the tree

         bool is_null_child(int k) const;
         // return true if k-th child is null

         B_Tree get_child(int k) const;
         // returns the k-th child of the tree
 
         int search ( Item_Type i );
         // returns the index where i occurs,
         // otherwise returns the child where i
         // could be inserted
   };
}
#include "mcs360_btree.tc"
#endif

