void InorderTraverse(BitTree T){
if(T){
InorderTraverse(T->lchild)
cout<<T->data;
InorderTraverse(T-<rchild)
}
}
void InorderTraverse(BitTree T){
StackInit(S)
p=T
while(p||!EmptyStack(S)){
if(p){
push(S,p)
p=p->lchild
}else{
q=pop(S)
cout<<q->data
p=q->rchild
}
}
}
void CreateBitTree(BitTree T){
cin>>ch;
if(ch=='#){
T=NULL
}else{
p=new BitNode
p->data=ch;
CreateBitTree(p->lchild)
CreateBitTree(p->rchild)
}
}
void CopyBitTree(BitTree T,BitTree &newT){
if(T==NUL){
newT=NULL;return;
}
newT=new BitNode;
newT->data = T->data
CopyBitTree(T->lchild,newT->lchild)
CopyBitTree(T->rchild,newT->rchild)
}
void Depth(BitTree T){
if(T==NULL){
return 0;
}
m=Depth(T->lchild);
n=Depth(T->rchild);
return m >n?m+1:n+1;
}
int NodeCount(BitTree T){
if(T==NULL){
return 0
}
return NodeCount(T->lchild)+NodeCount(T->rchild)
}
typedef struct BiThrNode{
int data;
BiThrNode *lchild,*rchild
int ltag,rtag
}BiThrNode,*BiThrTree
void InThreading(BiTHRTree p){
if(p){
InThreading(p->lchild)
if(!p->lchild){
p->ltag=1
p->lchild=pre
}else{
p->ltag=0
}
if(!pre->rchild){
pre->rtag=1
pre->rchild=p
}else{
pre->rtag=0
}
pre=p;
InThreading(p->rchild)
}
}
void InThreading(BitTree p){
Thr = new BitNode
Thr->ltag=0
Thr->ltag=1;
Thr->rchild=Thr
Thr->lchild=Thr
if(p){
Thr->lchild=p
pre = Thr
InThreading(p)
pre->rchild=Thr
Thr->rtag=1
Thr->rchild=pre
}
}
void InorderTraverse(BitTree T){
p=T->lchild
while(p!=T){
while(T->ltag==0){
p=p->lchild
}
cout<<p->data;
if(T->rtag==1&&p->lchild!=T){
p=p->rchild
cout<<P->data
}
p=p->rchild
}
}
void InorderTraverse(BitTree){
p=T_>lchild
while(p!=T){
while(p->ltag==0){
p=p->lchild
}
cout<<p->data;
while(p->rtag==1&&p->rchild!=T){
p=p->rchild
cout<<p->data
}
p=p->rchild
}
}
typedef struct {
int weight
int parent,lchild,rchild
}HTNOde,*HuffmnaTree
void CreateHuffManTree(HuffmnaTree &HT,int n){
if(n<=1){
return
}
m=2*n-1
HT=new HTNode[m+1]
for(i=1;i<=m;i++){
HT[i].parent=0;HT[i].lchild=0;HT[i].rchild=0
}
for(i=1;i<=n;i++){
cin>>TH[i].weight
}
for(i=n+1;i<=m;i++){
Select(HT,i-1,s1,s2)
HT[s1]->parent=sHT[s2].parent=i
HT[i].lchild=s1;
HT[i].rchild=s2
HT[i].weight=HT[s1].weight+HT[s2].weight
}
}
void CreateHuffmanCode(HuffmanTree HT,HuffmanCode &HC,int n){
HC = new char[n+1]
cd =new char[n]
cd[n-1]='\0'
for(i=0;i<=n;i++){
stat=n-1;c=i;f=HT[i].parent
while(f!=0){
--start;
if(HT[f].lchild==c){
cd[start]=0;
}else{
cd[start]=1
}
c=f;f=HT[f].parent
}
HC[i]=new char[n-start]
strCopt(HC[i],cd)
}
}
boolean check(BitTree T1,BitTree T2){
if(T1==NULL&&T2==NULL){
return true;
}else if(T1!=NULL&&T2!=NULL){
if(T1->data!=T2->data){
return false;
}
return check(T1->lchild,T2->lchild) && check(T1->rchild,T2->rchild)
}else{
return false;
}
}
void exchangeLR(BitTree T){
if(T){
*p=new BitNode();
p=T->lchild;
T->lchild=T->rchild
T->rchild=p
exchangeLR(T->lchild);
exchangeLR(T->rchild);
}
}
void InorderTraverse(BitTree T){
if(T==NULL){return;}
cout<<T->data;
InorderTraverse(T->lchild);
cout<<T->data;
InorderTraverse(T->rchild);
}
void Count(BitTree T){
if(T==NULL){return 0;}
while(T){
ListNode *p =new ListNode;
}
}