Home > Back-end >  Clues to the inside of the binary tree if (pre -> rchild==NULL && pre! Access conflict=NULL)
Clues to the inside of the binary tree if (pre -> rchild==NULL && pre! Access conflict=NULL)

Time:09-23

But if (pre!=NULL & amp; & The pre - & gt; Rchild) can be normal output is this why

CodePudding user response:

# include
# include
Typedef struct Treenode
{
char a;
Struct lchild Treenode * and * rchild;
Int ltag rtag;
} Treenode, * Bitree;
Void createtree (Bitree & amp; T) {
char a;
The scanf (" % c ", & amp; A);
If (a==' ') {

T=NULL;
}
The else {
T=(Bitree) malloc (sizeof (Treenode));
T - & gt; A=a;
T - & gt; Ltag=0;
T - & gt; Rtag=0;
Createtree (T - & gt; Lchild);
Createtree (T - & gt; Rchild);
}
}
Void creattt (Bitree & amp; T) {
T=(Bitree) malloc (sizeof (Treenode));
T - & gt; A='a';
T - & gt; Lchild=NULL;
T - & gt; Rchild=NULL;
}
Void visit (Bitree T) {
Printf (" % c ", T - & gt; A);
}

Void inthread (Bitree & amp; T, Bitree & amp; The pre) {
If (T!=NULL) {
Inthread (T - & gt; Lchild, pre);
If (T - & gt; Lchild==NULL) {
T - & gt; Lchild=pre;
T - & gt; Ltag=1;
}
If (pre!=NULL & amp; & The pre - & gt; Rchild==NULL) {
The pre - & gt; Rchild=T;
The pre - & gt; Rtag=1;
}
The pre=T;
Inthread (T - & gt; Rchild, pre);
}
}
Void creatthread (Bitree & amp; Tree) {

Bitree pre=NULL;
If (tree!=NULL) {
Inthread (tree, pre);
The pre - & gt; Rchild=NULL;
The pre - & gt; Rtag=1;
}
}
Treenode * Firstnode (Bitree T) {
While (T - & gt; Ltag==0) {
T=T - & gt; Lchild;
}
Return T;

}
Treenode * Nextnode (Bitree T) {
If (T - & gt; Rtag==0) {
Return Firstnode (T - & gt; Rchild);
}
The else {
Return T - & gt; Rchild;
}
}
Void inthreadorder (Bitree T) {
For (Treenode * p=Firstnode (T); p !=NULL; P=Nextnode (p)) {
Visit (p);
}

}
Int main () {
Bitree t;
Createtree (t);
Creatthread (t);
Inthreadorder (t);
return 0;

}

CodePudding user response:

If the pre is empty is wrong

CodePudding user response:

Because the calculation of the pre first!=NULL if the pre NULL will not calculate the pre - & gt; Rchild so that will not go wrong,
Whereas inevitable errors,
  • Related