我正在尝试查找给定密钥是否存在于二叉树中。如果密钥存在,我想 return 指向节点的指针

I am trying to find if a given key is present or not in a binary tree. I want to return the pointer to node if the key is present

我正在尝试查找给定键是否存在于二叉树中。如果密钥存在,我想 return 指向节点的指针。一旦找到密钥,我无法决定如何继承。

Node* findNode(Node*root,int ele){

    if(!root)
        return NULL;
    if(root->data==ele)
        return root;
    findNode(root->left,ele);
    findNode(root->right,ele);

}

I am unable to decide how to carry forward the key once found.

从函数中发扬某些东西的方法是return它。你可以改变

    findNode(root->left,ele);
    findNode(root->right,ele);

    Node *node;
    (node = findNode(root->left, ele)) || (node = findNode(root->right, ele));
    return node;