Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 修改函数内的结构指针_C_Pointers_Struct - Fatal编程技术网

C 修改函数内的结构指针

C 修改函数内的结构指针,c,pointers,struct,C,Pointers,Struct,我正在用C编写一个二进制搜索树的实现,下面是“插入”过程的一部分: void insert(void *key, struct bst *tree) { void n = NULL; struct bst **y = &n; struct bst **x = &(tree->root); struct bst *node = init(key); int cmp; while (*x != NULL) {

我正在用C编写一个二进制搜索树的实现,下面是“插入”过程的一部分:

void insert(void *key, struct bst *tree) {
    void n = NULL;
    struct bst **y = &n;
    struct bst **x = &(tree->root);
    struct bst *node = init(key);
    int cmp;

    while (*x != NULL) {
            y = x;
            cmp = <compare  node and x's key>
            if (cmp > 0)
                    x = &((*x)->left);
            else
                    x = &((*x)->right);
    }

    if (y == NULL) /* Empty Tree */
            tree->root = node;
    cmp = <compare node and y's key>

    else if (cmp > 0)
            (*y)->left = node;
    else
            (*y)->right = node;
void插入(void*键,结构bst*树){
void n=空;
结构bst**y=&n;
结构bst**x=&(树->根);
struct bst*node=init(键);
int-cmp;
而(*x!=NULL){
y=x;
cmp=
否则如果(cmp>0)
(*y)->左=节点;
其他的
(*y)->右=节点;
我使用双结构指针(x和y)来更改原始树。是否需要双指针,或者我是否可以使用指向树本身的简单指针来更改


编辑:在注释中得到了答案,我不需要指针。

您所显示的代码中不需要双指针。@CharlieBurns那么,一个简单的结构bst*x,*y就足够了吗?是的,并相应地更改其余部分。