添加指针到双指针 [英] Adding pointers to double pointer
问题描述
在树形控件中,我表示第一级节点(在我的树形控件中,第一,第二,第三),如下所示。
-
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屋!