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

/* This file defines a node in a B-tree.  There are two parameters
   that will be given as arguments of the template:

     Item_Type : the type of the key; and 
     numbchil : the number of children of every node. 

   This file is to be inserted as "an inner class"
   in the definition of a B-tree. 

   A test program for the definitions in this file
   has to define the "Item_Type" and the "numbchil".  */

#ifndef MCS360_BTREE_NODE_H
#define MCS360_BTREE_NODE_H

#define NULL 0

struct Node
{
   Item_Type data[numbchil-1];  // data stored at node

   int size; // number of data items, 0 <= size < numbchil-1

   Node* child[numbchil]; // pointers to the children

   // for all i: 0 <= i < size :
   //   d in subtree child[i] : d < data[i]
   // and
   //   d > data[size-2], for d in child[size-1].

   Node()  // constructor of node with no data
   {
      size = 0;
      for(int i=0; i<numbchil; i++)
      {
         if(i < numbchil-1) data[i] = Item_Type();
         child[i] = NULL;
      }
   }
};

#endif

