0
void insert_KD_tree(noKD **tree, Queue *queue, int counter) {


    if ((*tree)!=NULL) {
            *tree = new_KD_node(queue->first->pointer,NULL,NULL);
    }
    else if (((*tree)->pointer[counter]) > (queue->first->pointer[counter])) {
            counter++;
            insert_KD_tree(&(*tree)->left,queue);
    }
    else {
            counter++
            insert_KD_tree(&(*tree)->right,queue,counter);
    }
    pop(queue);
}

好的,所以这基本上是二叉树插入函数,但用于将数组插入节点。数组存储在队列中,但是指向指针的指针有问题。当我尝试使用 gdb 访问数组时,它会给出无法访问内存位置的消息0x10,但是如果我尝试在另一个函数上访问它,它会向我显示位置很好,我可以访问数组。

我注意到问题是指向指针事物的指针,如果我在调用时只放一个星号insert_KD_function,我的程序可以毫无问题地访问 tree->pointer。所以问题与指向指针的指针有关,它以某种方式丢失了指针引用。

谁能帮我?

4

1 回答 1

0
if ((*tree)!=NULL) {

Doesn't that mean that you overwrite the root if it exists? Shouldn't that be == NULL?

Apart from that, you should not that kd-trees don't perform very well on updates. If you have a lot of updates, you probably are better off with an R*-tree, which is balanced. Otherwise, pay attention to the structure of the tree, and bulk-load it again if it becomes too unbalanced.

于 2012-10-11T19:51:27.563 回答