求二叉树中值为x的结点的层号
【问题描述】
以二叉链表为存储结构,编写算法求二叉树中值为x的结点的层号。
【输入形式】两行,第一行是扩展二叉树的前序遍历序列,第二行是待查询结点x
【输出形式】值为x的结点所在层号。根结点所在层记为第1层。
【样例输入】AB#D##C##
D
【样例输出】
3
#include<iostream>
using namespace std;
template<typename DataType>
struct BiNode
{
DataType data;
BiNode<DataType> *lchild,*rchild;
};
template <typename DataType>
class BiTree
{
public:
BiTree()
{
root=Creat<