各位大侠,小弟的源程序如下,总是运行不起来,请指教!!谢谢
#include "iostream.h"
typedef enum{Link,Thread} PointerTag; //Link==0:指针,Thread==1:线索
typedef struct node
{
PointerTag LTag,RTag; //左右标记域
struct node *lchild,*rchild; //左右孩子域
char data; //数据域
}BiThrNode;
BiThrNode *createbintree();
void InThreading(BiThrNode *p);
void inorder(BiThrNode *t);
void InOrederThreading(BiThrNode *b);
void main()
{
BiThrNode *p;
p=createbintree();
inorder(p);
cout<<"\n";
InOrederThreading(p);
}
BiThrNode *createbintree()
{
BiThrNode *t;
char x;
cin>>x;
if(x=='#')
t=NULL;
else
{
t=new BiThrNode;
t->data=x;
t->lchild=createbintree();
t->rchild=createbintree();
}
return t;
}
void inorder(BiThrNode *t)
{
if(t!=NULL)
{
inorder(t->lchild);
cout<<t->data;
inorder(t->rchild);
}
}
void InThreading(BiThrNode *p)
{
BiThrNode *pre;
if(p)
{
pre=p;
if(p->lchild!=NULL)
InThreading(p->lchild);
if(!p->lchild)
{
p->LTag=Thread; //Link==0:指针,Thread==1:线索
p->lchild=pre;
}
if(!pre->rchild)
{
pre->RTag=Thread;
pre->rchild=p;
}
//pre=p;
InThreading(p->rchild);
}
}
void InOrederThreading(BiThrNode *b)
{
BiThrNode *pre,*a;
a=new BiThrNode;
a->LTag=Link; //Link==0:指针,Thread==1:线索
a->RTag=Thread;
a->rchild=a;
if(!b)
a->lchild=a;
else
{
a->lchild=b;
pre=a;
InThreading(b);
pre->rchild=a;
pre->RTag=Thread;
a->rchild=pre;
}
}