当前位置: 首页 >> 程序设计 >> 穿线二叉树源代码
 

穿线二叉树源代码

作者:      来源:http://blog.csdn.net/yunhaiC     发表时间:2007-06-12     浏览次数:      字号:    

typedef char datatype;
typedef struct node{
   datatype data;
   struct node *lchild,*rchild;
}bintnode;
typedef bintnode *binthrtree;
binthrtree root;

binthrtree pre=NULL;
void createbintree(binthrtree *t)
{char ch;
 if((ch=getchar())==' ')
    *t=NULL;
 else{
     *t=(binthrnode *)malloc(sizeof(binthrnode));
     (*t)->data=ch;
     createbintree(&(*t)->lchild));   //引用传递,要看清
     createbintree(&(*t)->rchild));
 }
}
void inthreading(binthrtree *p)
{if(*p)
 {inthreading(&((*p)->lchild));    //按照中序遍历先对左子树穿线遍历
  (*p)->ltag=((*p)->lchild)?0:1;   
  (*p)->rtag=((*p)->rchild)?0:1;
  if(pre)                                          //如果前序结点存在
  {if(pre->rtag==1)  pre->rchild=*p;
   if((*p)->ltag==1) (*p)->lchild=pre;
  }
  pre=*p;                                    //中序向前遍历下一个结点(链式存储)
  inthreading(&((*p)->rchild));
 }
}
void createthrtree(binthrtree *p)
{createbintree(p);
 inthreading(p);
}

责任编辑 webmaster

 
 
 
 
 
评论更多>>
 
 
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •