在二叉树中判断是否存在值为x的结点
【问题描述】
以二叉链表为存储结构,编写算法判断二叉树中是否存在值为x的结点。

【输入形式】两行,第一行是扩展二叉树的前序遍历序列,第二行是待查询结点x
【输出形式】如果结点x存在,则输出"YES";否则输出“NO”。
【样例输入】AB#D##C##
D
【样例输出】
YES
#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();
}
void InOrder()
{
InOrder(root)

本文介绍如何在以二叉链表为存储结构的二叉树中判断是否存在值为x的节点。算法基于输入的前序遍历序列进行分析,如果找到目标值x则输出'YES',否则输出'NO'。
最低0.47元/天 解锁文章
421





