添加指针到双指针 [英] Adding pointers to double pointer

查看:97
本文介绍了添加指针到双指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在树形控件中,我表示第一级节点(在我的树形控件中,第一,第二,第三),如下所示。




  • parent指向此结构的父节点。

  • children指向其所有子节点的指针数组。


typedef struct exp {    


int x;    


struct exp * parent;  


  struct exp ** children;


}


元素;



如何添加指针数组指向双指针  struct exp ** children.Dynamically我将添加和删除child,以便如何添加指针到双指针。


对于我的要求,子节点应该是双指针或单指针?


解决方案

您似乎是用C编码的。  ;假设你有一个名为tree的元素,那么你为指针分配空间,类似于
     tree.children = malloc(sizeof * tree.children * number_of_children);


然后为每个孩子分配空间,类似于
    for(j = 0;  j< number_of_children; j ++)

        {

   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; tree.children [j] = malloc(sizeof * three.children [j]);

        / *在刚刚分配的结构中存储值* / b
        }


Hi,

In tree control I am representing first level node(In my tree control, First, Second, Third) as follows.

  • parent points to the parent node of this structure.
  • children points to the array of pointers of all its child nodes.

typedef struct exp{    

int x;    

struct exp *parent;  

 struct exp **children;

}

element;

How to add array of pointers to double pointer  struct exp **children.Dynamically I will add and delete child so how to add add pointers to double pointer.

For my requirement the children node should be double pointer or single pointer?

解决方案

You appear to be coding in C.  Assuming you have an element named tree, then you allocate space for the pointers with something similar to
     tree.children = malloc(sizeof *tree.children * number_of_children);

You then allocate space for each child with something similar to
    for (j = 0; j < number_of_children; j++)
       {
        tree.children[j] = malloc(sizeof *three.children[j]);
        /* store values in the struct just allocated */
        }


这篇关于添加指针到双指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆