Source of TriNode.h


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: // Listing 19-1.

  6: /** A class of nodes for a link-based 2-3 tree.
  7:  @file TriNode.h */
  8:  
  9: #ifndef _TRI_NODE
 10: #define _TRI_NODE

 12: template<class ItemType>
 13: class TriNode
 14: {
 15: private:
 16:    ItemType smallItem, largeItem;    // Data portion
 17:    TriNode<ItemType>* leftChildPtr;  // Left-child pointer
 18:    TriNode<ItemType>* midChildPtr;   // Middle-child pointer
 19:    TriNode<ItemType>* rightChildPtr; // Right-child pointer
 20:    
 21: public:
 22:    TriNode();
 23:    TriNode(const ItemType& anItem);
 24:    TriNode(const ItemType& anItem, TriNode<ItemType>* leftPtr,
 25:            TriNode<ItemType>* midPtr, TriNode<ItemType>* rightPtr);
 26:    
 27:    bool isLeaf() const;
 28:    bool isTwoNode() const;
 29:    bool isThreeNode() const;
 30:    
 31:    ItemType getSmallItem() const;
 32:    ItemType getLargeItem() const;
 33:    
 34:    void setSmallItem(const ItemType& anItem);
 35:    void setLargeItem(const ItemType& anItem);
 36:    
 37:    TriNode<ItemType>* getLeftChildPtr() const;
 38:    TriNode<ItemType>* getMidChildPtr() const;
 39:    TriNode<ItemType>* getRightChildPtr() const;
 40:    
 41:    void setLeftChildPtr(TriNode<ItemType>* leftPtr);
 42:    void setMidChildPtr(TriNode<ItemType>* midPtr);
 43:    void setRightChildPtr(TriNode<ItemType>* rightPtr);
 44: }; // end TriNode
 45: #include "TriNode.cpp"
 46: #endif