Recursive Function Error: "-var-create: unable to create variable object"

Recursive Function Error: "-var-create: unable to create variable object"

我制作了一个二叉树来存储 2 个字符 'R' 和 'B'。插入和打印功能工作正常,但在执行搜索功能时,在 VS 代码的调试器工具下观察时,指针变量给出错误 -var-create: unable to create variable object

节点结构代码:

struct Node
{
    Node * left;
    Node * right;
    char value;
    bool endSeq = false;
};

BST 的搜索功能:

bool search(string k)
        {
            int len = k.length();
            bool found = false;
            searchHelper(root, k, len, found);
            if(found)
            {
                return true;
            }
            return false;
        }

Node * searchHelper(Node * p, string k, int & len, bool & found)
        {
            if(p == NULL)
            {
                return NULL;
            }
            else if(len == 0)
            {
                if(p->endSeq)
                {
                    found = true;       
                }
                return p;
            }
            else if(k[0] < p->value || (k[0] == 'B' && k[0] == p->value))
            {
                string kNew = k.substr(1, --len);
                if(p->endSeq)
                {
                    found = true;
                }
                else
                {
                    insertHelper(p->left, kNew, len);
                }
            }
            else if(k[0] > p->value || (k[0] == 'R' && k[0] == p->value))
            {
                string kNew = k.substr(1, --len);
                if(p->endSeq)
                {
                    found = true;
                }
                else
                {
                    insertHelper(p->right, kNew, len);   
                }
            }
            return p;
        }

你的代码有问题。您进行了错误的递归调用。您应该调用 searchHelper

而不是调用 insertHelper