/
interval_tree.h
55 lines (48 loc) · 1.19 KB
/
interval_tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <cstdlib>
#include <vector>
# ifndef Intervaltree_H
# define Intervaltree_H
using namespace std;
class BinaryRangeTree;
class Line;
class IntervalNode
{
public:
int x_mid;
vector<Line*> I_mid;
IntervalNode *left, *right;
BinaryRangeTree *rangetree;
IntervalNode() {
x_mid = 0;
left = NULL;
right = NULL;
rangetree = NULL;
}
IntervalNode(int x) {
x_mid = x;
left = NULL;
right = NULL;
rangetree = NULL;
}
};
class IntervalTree {
public:
IntervalNode *root;
IntervalTree() {
root = NULL;
}
vector<int> getSortedEndPointsX(vector<Line*> lines);
vector<int> getSortedEndPointsY(vector<Line*> lines);
void constructX(vector<Line*> lines);
void constructY(vector<Line*> lines);
IntervalNode* constructX(vector<Line*> lines, IntervalNode *node);
IntervalNode* constructY(vector<Line*> lines, IntervalNode *node);
void preorder(IntervalNode *r);
void preorder();
void queryX(int maxX, int minX, int x, int y1, int y2, IntervalNode* node);
void queryX(int maxX, int minX, int x, int y1, int y2);
void queryY(int maxY, int minY, int y, int x1, int x2, IntervalNode* node);
void queryY(int maxY, int minY, int y, int x1, int x2);
};
#endif