I was reading a kd tree implementation in C.Here is some parts of it.The problem is in findmedian function.I dont understand the implementation of
*md = start +(end-start)/2;
...... -> Other irrelevant lines of code
struct kd_node_t
{
double x[3];
struct kd_node_t *left, *right;
};
struct kd_node_t* findmedian(struct kd_node_t *start, struct kd_node_t *end, int idx)
{
......
struct kd_node_t *p, *store, *md = start + (end - start) / 2;
......
}
Hm, what is implemented here is just the "half-way between the two pointers" start
and end
. If the implementation takes care that there is a meaningful value at this position in memory (which might be a median) then you're lucky, otherwise you get garbage...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.