-
Notifications
You must be signed in to change notification settings - Fork 2
/
kdTree.cpp
65 lines (54 loc) · 1.07 KB
/
kdTree.cpp
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
56
57
58
59
60
61
62
63
64
65
/*
* File: kdTree.cpp
* Author: Koray Gocmen
*
* Created on March 25, 2016, 1:47 PM
*/
#include "kdTree.h"
#include <cstddef>
using namespace std;
class kdTree;
kdTree::kdTree() {
root = NULL;
}
kdTree::kdTree(const kdTree& orig) {
}
kdTree::~kdTree() {
if(root != NULL){
delete root;
}
root = NULL;
}
kdTreeNode* kdTree::getRoot(){
return root;
}
void kdTree::insert(kdTreeNode* newEntry){
if(root == NULL){
//tree is empty
newEntry->setLevel(true); //set the root to x-level
newEntry->setParent(NULL); //set parent
root = newEntry;
}else{
root->insertNode(newEntry, root);
}
}
void kdTree::remove(kdTreeNode* entry){
if(root == NULL)
return;
else{
root->removeNode(entry, root);
}
}
kdTreeNode* kdTree::findClosestPoint(kdTreeNode* entry){
if(root == NULL)
return NULL;
else{
return(root->findClosestNode(entry));
}
}
void kdTree::print(){
if(root == NULL)
return;
else
root->printNodes();
}