#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: