typedef enum
{
_LEFT_LEFT, //the new node insert in the left tree of the left node
_LEFT_RIGHT, //the new node insert in the left tree of the right node
_RIGHT_RIGHT,//the new node insert in the right tree of the right node
_RIGHT_LEFT, //the new node insert in the right tree of the left node
_BALANCE //the tree is balance
}_NOBALANCE_TYPE;
template<class typeKey>
class CAvlTreeIndex
{
typedef CAvlTreeNode<typeKey> node;
private:
node* head; //the head node of the a v l tree
public:
CAvlTreeIndex(){}
explicit CAvlTreeIndex(typeKey value)
{
head = new node(value);
}
// insert one node into the a v l tree
void insert_Node(typeKey value);
//delete a node whose value is value from the a v l tree
void delete_Node(typeKey value);
//get the location of the node whose value is value
//if the node is in the a v l tree ,return the node
//else return null
CAvlTreeNode<typeKey>* find_key_inTree(typeKey value)const;
bool is_key_inTree(typeKey value) const;
//find the parent of the node which will be inserted
inline CAvlTreeNode<typeKey>* getParent_InsertNode(typeKey value ,bool& isInLeftChild) const;
//after insert the node ,adjust the tree to balance
inline void adjust_avl_tree(node* parent ,bool isLeftNode ,bool increase = true);
//deal with the condition of left - left
inline void rotate_cond_ll(node* rotate_node);
//deal with the condition of left - right
inline void rotate_cond_lr(node* rotate_node);
//deal with the condition of right - left
inline void rotate_cond_rl(node* rotate_node);
//deal with the condition of right - right
inline void rotate_cond_rr(node* rotate_node);
void print()
{
print(head);
}
void print(node* head)
{
if(head != 0)
{
print(head->left_child_node);
cout<<head->value_node<<" "<<head->deepth<<endl;
print(head->right_child_node);
}
}
~CAvlTreeIndex();
};
#endif