Home > Back-end >  First order recursive output within a depth of three binary tree nodes all ancestors of arbitrary
First order recursive output within a depth of three binary tree nodes all ancestors of arbitrary

Time:06-08

#include
#include
Typedef struct BiTNode {char data; Struct lchild BiTNode * and * rchild; } BiTNode, * BiTree;
Int fun (BiTree T, char data)
{if (T - & gt; data=https://bbs.csdn.net/topics/=data) return 1; If (T -> lchild==NULL && T -> rchild==NULL) {return 0; }///add loop: after the if (fun (T -> rchild, data) | | fun (T -> lchild, data))
% c {printf (" * ", T - & gt; The data); data=https://bbs.csdn.net/topics/T-> data; }
The else {the if (T - & gt; Lchild - & gt; Lchild!=NULL) {T - & gt; Lchild - & gt; Rchild=T - & gt; Lchild - & gt; Lchild; } the if (T - & gt; Rchild - & gt; Rchild!=NULL) {T - & gt; Rchild - & gt; Lchild=T - & gt; Rchild - & gt; Rchild; } goto loop; }} int preoutput (BiTree T)
{if (T!=NULL)
{printf (" % c ", T - & gt; The data);
Preoutput (T - & gt; Lchild); Preoutput (T - & gt; Rchild); };
return 0; }
Void CreateBiTree (BiTree * T) {char ch; The scanf (" % c ", & amp; ch); If (ch=='#') * T=NULL; The else {* T=(BiTree) malloc (sizeof (BiTNode)); If (* T==NULL)//==if (! * T) exit (1);//out of the (* T) - & gt; data=https://bbs.csdn.net/topics/ch; CreateBiTree (& (* T) -> lchild); CreateBiTree (& (* T) -> rchild); }}
Int main () {BiTree T; Int flag=0; Char data='https://bbs.csdn.net/topics/f'. CreateBiTree (& amp; T); Printf (" first sequence output \ n "); Preoutput (T); Printf (" ancestor nodes: "); Fun (T, data); printf("\n"); return 0; }

CodePudding user response:

Code a mass of linen,
Don't know if this is what you want, https://blog.csdn.net/pfdvnah/article/details/102387839
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1, if the problem has been solved, please post in a timely manner, the , the
2, if no problem, can continue to cross-examine,
3, only on the computer and posted on the web, mobile phone cannot bear,
CSDN BBS newbie guide
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

reference 1st floor wowpH response:
code a mass of linen,
Don't know if this is what you want, https://blog.csdn.net/pfdvnah/article/details/102387839
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1, if the problem has been solved, please post in a timely manner, the , the
2, if no problem, can continue to cross-examine,
3, only on the computer and posted on the web, mobile phone cannot bear,
CSDN BBS newbie guide
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Post for the first time, don't know how to standardize to one line,

CodePudding user response:

Char c=o f the ancestor nodes' f '

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related