判断一个节点是否在一棵二叉树中

来源:互联网 发布:mac如何隐藏照片 编辑:程序博客网 时间:2024/06/04 00:23

使用前序遍历判断

struct Node{    int _data;    Node* _left;    Node* _right;    Node(const int& x)        : _data(x)        , _left(NULL)        , _right(NULL)    {}};bool IsExist(Node* root, Node* point){    if (root == NULL)        return false;    if (point->_data == root->_data)        return true;    bool IsInLeft = IsExist(root->_left, point);    if (IsInLeft == true)        return true;    else        return IsExist(root->_right, point);}
阅读全文
0 0