Home > database >  According to sequence in the first sequence traversal and after traversing binary tree is establishe
According to sequence in the first sequence traversal and after traversing binary tree is establishe

Time:09-26

Why is wrong the following
# include & lt; Iostream>
using namespace std;
Struct BiNode
{
Char data;
Lchild BiNode * and * rchild;
};
The class BiTree
{
Public:
BiTree (char [], a char [] b, int k)
{
For (int I=0; i The pre=[I] a [I];
For (int I=0; i Pin [I] [I]=b;
Root=the Create (root, 0, 0, k);
}
~ BiTree () {Release (root); }
Void PreOrder () {PreOrder (root); }
Void InOrder () {InOrder (root); }
Void PostOrder () {PostOrder (root); }
Int the find (char d, char [], e int f, int k);
Private:
Char pre [100], pin [100];
BiNode * root;
Create BiNode * (BiNode * root, int i1, int i2, int k);
Void Release (bt) BiNode *;
Void PreOrder (BiNode * root);
Void InOrder BiNode * (bt);
Void PostOrder (BiNode * root);
};
BiNode * BiTree: : Create (BiNode * root, int i1, int i2, int k)
{
int m;
Int rightlen leftlen;
If (k & lt;=0)
The root=NULL;
The else
{
The root=new BiNode;
Root - & gt; Data=https://bbs.csdn.net/topics/pre (i1);
M=find (pre (i1), pin, i2, k);
Leftlen=m - i2;
Rightlen=k - (leftlen + 1);
Root - & gt; Lchild=the Create (root - & gt; Lchild, i1 + 1, i2, leftlen);
Root - & gt; Rchild=the Create (root - & gt; Rchild, i1 + leftlen + 1, m + 1, rightlen);

}
return root;
}
Void BiTree: : Release (bt) BiNode *
{
If (bt!!!!=NULL)
{
Release (bt - & gt; Lchild);
Release (bt - & gt; Rchild);
Delete the bt;
}
}
Int BiTree: : find (char d, char [], e int f, int k) {
For (int I=f; i[I] if (e==d) return the I;
}
}
Void BiTree: : PostOrder (BiNode * root)
{
If (root==NULL)
{
return;
}
The else
{
PostOrder (root - & gt; Lchild);
PostOrder (root - & gt; Rchild);
Cout & lt; }
}
Int main ()
{
String a, b;
Int z;
[100] char ai, bi [100];
Cin & gt;> A. & gt;> b;
Int Lena=a.s considering ();
Int lenb=b.s considering ();
For (int I=0; i {
Ai=[I] a [I];
}
For (int I=0; i {
Bi [I] [I]=b;
}
BiTree c (ai, bi, Lena);
C.P ostOrder ();

return 0;
}
  • Related