博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

建立中序线索二叉树

Posted on 2012-11-22 10:48  皇星客栈--Linux  阅读(241)  评论(0编辑  收藏  举报
View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 typedef int DataType;
 4 
 5 typedef struct BiThrNode{
 6     DataType data;
 7     struct BiThrNode *lchild;
 8     struct BiThrNode *rchild;
 9     unsigned ltag;
10     unsigned rtag;
11 }BiThrNode,*BiThrTree;
12 
13 BiThrTree pre;
14 
15 void InThreading(BiThrTree p){
16     if(p){
17     InThreading(p->lchild);
18     if(!(p->lchild)){
19     p->ltag=1;
20     p->lchild=pre;
21     }
22     if(!pre->rchild){
23     pre->rtag=1;
24     pre->rchild=p;
25    }
26    pre=p;
27    InThreading(p->rchild);
28   }
29 }
30 int InOrderThr(BiThrTree *head,BiThrTree T){
31     (*head)=new BiThrNode;
32     if(!(head))
33         return 0;
34     (*head)->ltag=0;
35     (*head)->rtag=1;
36     (*head)->rchild=(*head);
37     if(!T)
38     (*head)->lchild=*head;
39     else{
40     (*head)->lchild=T;
41     pre=*head;
42     InThreading(T);
43     pre->rchild=*head;
44     pre->rtag=1;
45     (*head)->rchild=pre;
46     }
47     return 1;
48 }
49 
50 int main( )
51 {
52     BiThrTree T;
53     BiThrTree *head;
54     return 0;
55 }
56     
57