回 帖 发 新 帖 刷新版面

主题:请教一道中序线索二叉树题目

在一棵中序线索二叉树中将t插入,作为原结点s的右孩子的算法如下:
Insertrightchild(bitreepointer s,bitreepointer t)
{
  t->rightchild=s->rightchild;
  t->righttag=s->righttag;
  t->leftchild=s;
  t-lefttag=1;
  if(s->righttag==0)
  {
    bitreepointer p =s->rightchild;
    while(p->lefttag==0)
     {
       p=  1  ;
       if(p->lefttag==1)     2       ;
     }
   s->rightchild=       3      ; 
   s->righttag=0;
   }
}

我的答案是:1、p->leftchild;
            2、p->leftchild=t;
            3、t;
各位能帮我看看,我做的对吗?

回复列表 (共5个回复)

沙发

怎么没人帮帮我

板凳

苦等好人出现啊

3 楼

Insertrightchild(bitreepointer s,bitreepointer t)
{
  t->rightchild=s->rightchild;/*连第一根右线*/
  t->righttag=s->righttag;/*赋标志*/
  t->leftchild=s;/*t的左孩子线索化*/
  t-lefttag=1;
  if(s->righttag==0)
  {
    bitreepointer p =s->rightchild;/*当时s的右孩子还是原来的*/
    while(p->lefttag==0)
     {
       p=  1  ;/*一直寻找左孩子*/
       if(p->lefttag==1)     2       ;/*左孩子线索化*/
     }
   s->rightchild=       3      ; /*连上第二根线*/
   s->righttag=0;
   }
}

我的答案是:1、p->leftchild;
            2、p->leftchild=t;
            3、t;


正确
总体来说4根线改变了
似乎没考虑特殊情况
你哪里来的代码,自己写的?

   

4 楼

一般能照着抄抄代码也已经不错了,剩下的就是调试成功.

5 楼

终于看到有人帮我了,太谢谢了。

这个不是我写的代码,是我报考的学校去年的专业课试题,因为没有答案所以求证一下

我来回复

您尚未登录,请登录后再回复。点此登录或注册