有什么区别[insert_node(&(tmp-> left),value);] VS [tmp = tmp-> right; insert_node(&(TMP),值);]插入二叉树的方法
void insert_node(struct btree **bt,int value)
{
btree *tmp= *bt, *r ;
if(*bt==NULL)// first node
{
(*bt)=(struct btree *)malloc(sizeof(btree));
(*bt)->data=value;
(*bt)->left=NULL;
(*bt)->right=NULL;
}
else
{
if(value > tmp->data)
insert_node(&(tmp->right),value);
else
insert_node(&(tmp->left),value);
}
#if 0 //start
OR /** COMMENT START
earlier I had below piece of code but not working
can any please explain what's the difference in
insert_node(&(tmp->left),value); VS [ tmp=tmp->right; insert_node(&(tmp),value);]
COMMENT END **/
else
{
if(value > tmp->data)
tmp=tmp->right;
else
tmp=tmp->left ;
insert_node(&tmp,value);
}
#endif //end
}
什么喜弗朗西斯但调用我通过适当的值初始化我之前TMP TMP = TMP->左,TMP->右键然后我按地址传递。你能解释一下吗? – 2011-12-26 06:31:23
是的,tmp指向tmp-> right指向的任何东西,但是你正在修改tmp中的指针(因为你给出了tmp的地址),并且你想要修改的是指针tmp->正确(在工作示例中给出了该地址)。 – 2011-12-26 06:33:17