// File RBTree. h
// Written by saturnman
# Ifndef _ RB_TREE_H _
# Define _ RB_TREE_H _
# Include <iostream>
# Include <string>
# Include <sstream>
# Include <fstream>
Using namespace std;
Template <class KEY, class U>
Class RB_Tree
{
Private:
RB_Tree (const RB_Tree & input ){}
Const RB_Tree & operator = (const RB_Tree & input ){}
Private:
Enum COLOR {RED, BLACK };
Class RB_Node
{
Public:
RB_Node ()
{
RB_COLOR = BLACK;
Right = NULL;
Left = NULL;
Parent = NULL;
}
COLOR RB_COLOR;
RB_Node * right;
RB_Node * left;
RB_Node * parent;
KEY key;
U data;
};
Public:
RB_Tree ()
{
This-> m_nullNode = new RB_Node ();
This-> m_root = m_nullNode;
This-> m_nullNode-> right = this-> m_root;
This-> m_nullNode-> left = this-> m_root;
This-> m_nullNode-> parent = this-> m_root;
This-> m_nullNode-> RB_COLOR = BLACK;
}
Bool Empty ()
{
If (this-> m_root = this-> m_nullNode)
{
Return true;
}
Else
{
Return false;
}
}
// Find node whos key equals to key, else find the insert point;
RB_Node * find (KEY key)
{
RB_Node * index = m_root;
While (index! = M_nullNode)
{
If (key <index-> key)
{
Index = index-> left;
}
Else if (key> index-> key)
{
Index = index-> right;
}
Else
{
Break;
}
}
Return index;
}
Bool Insert (KEY key, U data)
{
RB_Node * insert_point = m_nullNode;
RB_Node * index = m_root;
While (index! = M_nullNode)
{
Insert_point = index;
If (key <index-> key)
{
Index = index-> left;
}
Else if (key> index-> key)
{
Index = index-> right;
}
Else
&