草稿笔记为:
通过kd树的部分代码为
#include <iostream>
#include <vector>
using namespace std;
void select_sort(vector<float> vec){
int n = vec.size();
for(int j = 0;j<n;j++){
int min = vec[j];
int index = j;
for(int i=j+1;i<n;i++){
if(min<vec[i]){
min = vec[i];
index = i;
}
}
int tmp = vec[index];
vec[index] = vec[j];
vec[j] = tmp;
}
}
float get_vector_median(vector<float> vec){
int n = vec.size();
select_sort(vec);
if(n%2!=0){
return vec[n/2];
}else{
return (vec[(n-1)/2]+vec[n/2])/2;
}
}
class dataset{
private:
vector<vector<float>> data;
public:
//load data
dataset(){
}
//构建kd树
void kd_tree(){
}
};
int main(){
return 0;
}
自行体会编码过程。。。