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 }