#include <iostream>
using namespace std;
struct brTree {
char data;
brTree *lchild;
brTree *rchild;
};
void creatTree(brTree *&tree)
{
char c;
cin >> c;
if (c == '#')
{
tree = NULL;
}
else
{
tree = new brTree;
tree->data = c;
creatTree(tree->lchild);
creatTree(tree->rchild);
}
}
void getTree(brTree *tree, int &count)
{
if (tree == NULL)
{
return;
}
if (tree->rchild != NULL)
{
count++;
getTree(tree->rchild, count);
}
}
int maxcount = 0;
void gedDegree(brTree *tree, int Count)
{
if (tree == NULL)
{
return;
}
if (tree->rchild)
{
gedDegree(tree->rchild, Count + 1);
}
else
{
if (Count > maxcount)
{
maxcount = Count;
}
}
if (tree->lchild)
{
gedDegree(tree->lchild, 0);
}
}
int max = 0;
int main()
{
brTree *tree = NULL;
creatTree(tree);
if (tree->rchild != NULL)
{
cout << "ERROR";
}
else
{
gedDegree(tree, 0);
cout << maxcount + 1;
}
return 0;
}
最后修改:2019 年 04 月 10 日
© 允许规范转载