Home > Back-end >  Clues about binary tree of small problems, kindly pass bosses grant instruction!!!!!!!!!!
Clues about binary tree of small problems, kindly pass bosses grant instruction!!!!!!!!!!

Time:09-16

 public void threadedPreNodes (HeroNode node) {
//if the node==null, exit
If (node==null) {
return;
}
//deal with the current node of the precursor node
If (node. GetLeft ()==null) {
//to the current node pointer to precursor, and to the left of the node
Node. SetLeft (pre);
//modify the left of the current node pointer type
Node. SetLeftType (1);//the left pointer to precursor node
}

//processing subsequent node
If (pre!=null & amp; & The pre. GetRight ()==null) {
The pre. SetRight (node);
The pre. SetRightType (1);
}
//for each node processing, after the pre should follow the node
The pre=node;

//clues left subtree
If (node. GetLeftType ()!=1) {
ThreadedPreNodes (node getLeft ());
}
//clues right subtree
If (node. GetRightType ()!=1) {//why this if can not get rid of?
ThreadedPreNodes (node getRight ());
}
}

recent data tree structural to the clues, clues as before is to write a preface tree method,
As above 27 rows if judge: why can't I remove? I feel logic from the paper several times to remove is no problem, right node connection is responsible for the work is handed over to the next element, as in the element, node is empty, right reason into the recursion will also by 3 rows if exit, but run if remove seems unable to quit recursion,
Appreciate!!!!!!!!!! The problem was I too bad! Thank you very much!!!!!!!!!!!

CodePudding user response:

After the clues for the original node will add precursor and the subsequent!
 if (node getLeft ()==null) {
//to the current node pointer to precursor, and to the left of the node
Node. SetLeft (pre);//before not now have led you here not to judge the type! Has been not null=1
//modify the left of the current node pointer type
Node. SetLeftType (1);//the left pointer to precursor node
}

So if your 3 line never retreat

CodePudding user response:

reference 1st floor YangjulongTrue response:
after the clues of the original node will add precursor and the subsequent!
 if (node getLeft ()==null) {
//to the current node pointer to precursor, and to the left of the node
Node. SetLeft (pre);//before not now have led you here not to judge the type! Has been not null=1
//modify the left of the current node pointer type
Node. SetLeftType (1);//the left pointer to precursor node
}

So if your 3 line never back

Left subtree I know after setting can have influence, so to judge,
My problem is that the right subtree why also need if the judgement? When of clues to the right of the connection is only when the node to the next node, in other words, when the node on the current node on the right is empty, why not perform third row if recursion?

CodePudding user response:

Was no nodes is indeed the right
But after the call the method leads the left subtree themselves (recursive) after your current node is pre
As long as the
 
As long as there is value and meet the left node is added node
If (pre!=null & amp; & The pre. GetRight ()==null) {
The pre. SetRight (node);
The pre. SetRightType (1);
}
the methods do not give the pre set in the right node (equivalent to the outside of the node has a right node) out after the node getRight (), it is not null has been clues turn out not to come

CodePudding user response:

//clues left subtree 
If (node. GetLeftType ()!=1) {
ThreadedPreNodes (node getLeft ());
}
//clues right subtree
ThreadedPreNodes (node getRight ());

I mean it, why not left subtree of the if statement is to filter out the sort of condition that you say, at this time for clues right subtree of the recursion into after total it is null,

CodePudding user response:

You have only one node? If only one so there is no problem is null didn't things

But if there are two A and A B, and to the left of the node to A pre null
A in the first three if not into the pre=A went straight to the clues in the left subtree method
B in tie precursor node B left for tying A right for subsequent node B let pre for B//attention at this time had the right node
Judge node. GetLeftType ()!=1 to 1 false not to cable turn left subtree is
Clues to turn right to the current node into B B.r d.light stack is empty out
To A A has the right node won't jump out because you have no judgment node. GetRightType ()!=1 are clues

CodePudding user response:

If you really don't know can debug see you know why

CodePudding user response:

refer to 7th floor YangjulongTrue response:
you have only one node? If only one so there is no problem is null didn't things

But if there are two A and A B, and to the left of the node to A pre null
A in the first three if not into the pre=A went straight to the clues in the left subtree method
B in tie precursor node B left for tying A right for subsequent node B let pre for B//attention at this time had the right node
Judge node. GetLeftType ()!=1 to 1 false not to cable turn left subtree is
Clues to turn right to the current node into B B.r d.light stack is empty out
To A A has the right node won't jump out because you have no judgment node. GetRightType ()!=1 whether have clues

Oh ~ I see, thank you, thank you super
  • Related