// L-35 MCS 360 Fri 12 Nov 2010 : mcs360_btree.tc /* This file defines the members of the templated class B_Tree in the namespace mcs360_btree. */ namespace mcs360_btree { template < typename Item_Type, int numbchil > B_Tree::B_Tree() { root = NULL; } template < typename Item_Type, int numbchil > B_Tree::B_Tree( int n, Item_Type *a ) { root = new Node; root->size = n; for(int i=0; idata[i] = a[i]; } template < typename Item_Type, int numbchil > B_Tree::B_Tree( int n, Item_Type *a, B_Tree *c ) { root = new Node; root->size = n; for(int i=0; idata[i] = a[i]; root->child[i] = c[i].root; } root->child[n] = c[n].root; } template < typename Item_Type, int numbchil > int B_Tree::get_size() { return root->size; } template < typename Item_Type, int numbchil > Item_Type* B_Tree::get_data() { return root->data; } template < typename Item_Type, int numbchil > bool B_Tree::is_null_child(int k) const { return (root->child[k] == NULL); } template < typename Item_Type, int numbchil > B_Tree B_Tree::get_child(int k) const { B_Tree b; b.root = root->child[k]; return b; } template < typename Item_Type, int numbchil > int B_Tree::binary_search (int first, int last, Item_Type i) { if(first == last) return first; else { int middle = (first + last)/2; if(i == root->data[middle]) return middle; else if(i < root->data[middle]) return binary_search(first,middle,i); else return binary_search(middle+1,last,i); } } template < typename Item_Type, int numbchil > int B_Tree::search ( Item_Type i ) { int L = root->size-1; if(i > root->data[L]) return L+1; else return this->binary_search(0,L,i); } }