20176401测绘17-1段建国数据结构第五章

20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
20176401测绘17-1段建国数据结构第五章
#include
using namespace std;
template
struct BiNode
{
T data;
BiNode *lchild,*rchild;
};
template
class BiTree
{
public:
BiTree(){root=NULL;}
BiTree(BiNode*root);
~BiTree();
void PreOrder(BiNode*root);
void InOrder(BiNode*root);
void PostOrder(BiNode*root);
private:
BiNode*root;
void Great(BiNode*root);
void Release(BiNode*root);
};
template
void BiTree::PreOrder(BiNode*root)
{
if(rootNULL) return;
else{
cout<data;
PreOrder(root->lchild);
PreOrder(root->rchild);
}
}
template
void BiTree::InOrder(BiNode*root)
{
if(root
NULL) return;
else{
InOrder(root->lchild);
cout<data;
InOrder(root->rchild);
}
}
template
void BiTree::PostOrder(BiNode*root)
{
if(rootNULL) return;
else{
PostOrder(root->lchild);
PostOrder(root->rchild);
cout<data;
}
}
template
BiTree::BiTree(BiNode*root)
{
Creat(root);
}
template
BiTree::~BiTree(void)
{
Release(root);
}
int n=0;
template
void Count(BiNode*root)
{
if(root){
Count(root->lchild);
n++;
Count(root->rchild);
}
}
template
void PreOrderleaf(BiNode*root)
{
if(root){
if(root->lchild&&root->rchild)
cout<data;
PreOrderleaf(root->lchild);
PreOrderleaf(root->rchild);
}
}
template
void Depth(BiNode*root)
{
if(root
NULL) return 0;
else{
int hl=Depth(root->lchild);
int hr=Depth(root->rchild);
return hl>hr?hl+1:hr+1;
}
}
int main()
{
int a[5]={1,2,3,4,5};
BiTree A();
return 0;
}