app.cpp
来自「C++编写的二叉树程序」· C++ 代码 · 共 31 行
CPP
31 行
#include "Tree1.h"
void property3(TreeNode1 *p,int &n0,int &n2)
{
if(p!=NULL)
{
if(p->left==NULL && p->right==NULL)//leaf node
n0++;
if(p->left==NULL && p->right==NULL)//2 degree leaf node
n2++;
property3(p->left,n0,n2);
property3(p->right,n0,n2);
}
}
void main()
{
char *str="ABCDEFGH";
cout<<"The TreeL "<<str<<endl;
Tree1 t1(str);
t1.preorder();
t1.inorder();
t1.postorder();
int n0=0,n2=0;
property3(t1.root,n0,n2);
cout<<"check the feature3 of the binary tree, ";
cout<<"n0="<<n0<<", n2="<<n2<<", n0==n2+1 ? ";
if(n0==n2+1)
cout<<"correct"<<endl;
else
cout<<"false"<<endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?