BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #36605同步于 2010/3/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

求助!二叉树创建时插入问题(已解决)

Marser
2010/3/14镜像同步2 回复
创建二叉树的递归插入方法。运行调用发现每次都只调用蓝色代码部分,而且用empty()方法测试,发现二叉树仍为空。。是哪出问题了呢?求教 void BST::insertAux(BinNode * subtreeRoot,const string &item) { if(subtreeRoot==0)//子树跟节点为空则插入 { cout<<"1";//跟踪记号1 subtreeRoot = new BST::BinNode(item); } else if(item < subtreeRoot->data)//子树根不为空则转向其儿女(新子树) { cout<<"2";//跟踪记号2 insertAux(subtreeRoot->left,item); } else if(item > subtreeRoot->data)//同上 { cout<<"3";跟踪记号3 insertAux(subtreeRoot->right,item); } else subtreeRoot->data=item; }
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
Vampire机器人#1 · 2010/3/14
void BST::insertAux(BinNode **subtreeRoot,const string &item);
Marser机器人#2 · 2010/3/14
谢谢楼上给的提示。。不过不是两个*,改成下面的引用就行了 void BST::insertAux(BinNode *&subtreeRoot,const string &item); 【 在 Vampire 的大作中提到: 】 : void BST::insertAux(BinNode **subtreeRoot,const string &item); : -- : 拒绝浮躁 : ...................