int n
= 0;
void count(BTNode
*p
){
if(p
!=NULL){
++n
;
count(p
->lchild
);
count(p
->rchild
);
}
}
int n
= 0;
void count_0(BTNode
*p
){
if(p
!=NULL){
if(p
->lchild
=NULL&&p
->rchild
=NULL)
++n
;
count_0(p
->lchild
);
count_0(p
->rchild
);
}
}
void link(NTNode
*p
, BTNode
*&head
, BTNode
*&tail
){
if(p
!=NULL){
if(p
->lchild
!=NULL&&p
->rchild
!=NULL){
if(head
==NULL){
head
=p
;
tail
=p
;
}
else{
tail
->rchild
=p
;
tail
=p
;
}
}
link(p
->lchild
,head
,tail
);
link(p
->rchild
,head
,tail
);
}
}
typedef struct BTNode
{
char data
;
BTNode
*lchild
;
BTNode
*rchild
;
BTNode
*parent
;
}
void triBtree(BTNode
*p
, BTNode
*q
){
if(p
!=NULL){
p
->parent
= q
;
q
= p
;
triBtree(lchild
,q
);
triBtree(rchild
,q
);
}
}
void printPath(BTNode
*p
){
while(*p
!=NULL){
cout
<<p
->data
<<'\n';
printPath(p
-parent
);
}
}
void allPath(BTNode
*p
){
if(p
!=NULL){
printPath(p
);
allPath(p
->lchild
);
allPath(p
->rchild
);
}
}
void change(char pre
[], int L1
, int R1
, char post
[], int L2
, int R2
){
if(L1
<=R1
){
post
[R2
] = pre
[L1
]; change(pre
, L1
+1, (L1
+1+R1
)/2, post
, L2
,(L2
+R2
-1)/2);
change(pre
, L1
+1, (L1
+1+R1
)/2, post
, L2
,(L2
+R2
-1)/2);
change(pre
, L1
+1, (L1
+1+R1
)/2, post
, L2
,(L2
+R2
-1)/2);
}
}
int L
=1;
void leno(BTNode
*p
){
if(p
!=0){
if(p
->data
==b
)
cout
<<L
<<endl
;
++L
;
leno(p
->lchild
);
leno(p
->rchild
);
--L
;
}
}
TBTNode
* inLast(TBTNode
*t
){
TBTNode
*p
= t
;
while(p
&& !p
->rtag
){
p
= p
->rchild
;
}
return p
;
}
TBTNode
* inPrior(TBTNode
*t
){
TBTNode
*p
=t
->lchild
;
if(p
&& !t
->ltag
){
p
=inLast(p
);
}
retunr p
;
}
TBTNode
* treNext(TBTNode
*t
){
TBTNode
*p
;
if(!t
->ltag
)
p
= t
-lchild
;
else if(!tag
->rtag
)
p
= t
-rchild
;
else{
p
= t
;
while(p
&& p
-rtag
)
p
=p
->rchild
;
if(p
)
p
=p
->rchild
;
}
return p
;
}
转载请注明原文地址:https://tech.qufami.com/read-6693.html