OneKdTree.h
#include <algorithm>
#include <set>
#include <iostream>
using namespace std;
class AvlTree;
class AvlNode{
friend class AvlTree;
int data;
int height;
AvlNode *left;
AvlNode *right;
AvlNode(int _data) :data(_data), height(0), left(NULL), right(NULL){}
};
class AvlTree{
AvlNode *root;
public:
AvlTree() :root(NULL){}
int Height(AvlNode *node){ return node == NULL ? -1 : node->height; }
void Insert(int _data){ _insert(root, _data); }
void Delete(int _data){ _delete(root, _data); }
bool Find(int _data);
void print(){ travel(root); cout << endl; }
void OneDRangeQuery(int low, int high);
private:
AvlTree(const AvlTree &);
AvlTree& operator=(const AvlTree&);
void LL(AvlNode* &node);
void RR(AvlNode* &node);
void RL(AvlNode* &node);
void LR(AvlNode* &node);
void _insert(AvlNode* &node,int _data);
void _delete(AvlNode* &node, int _data);
void travel(AvlNode *node);
AvlNode *FindMin(AvlNode *node);
AvlNode *FindParent(AvlNode *node, int _data);
void ParentRotate(AvlNode* &node, AvlNode* &parent);
void LeftHigherhanRight(AvlNode* &node);
void RightHigherhanLeft(AvlNode* &node);
AvlNode* FindSplitNode(int low, int high);
};
void AvlTree::OneDRangeQuery(int low, int high)
{
AvlNode *node = FindSplitNode(low, high);
if (node == NULL)
return;
if (node->left == NULL&&node->right == NULL){
if (node->data >= low && node->data <= high)
cout << node-&g