简体   繁体   English

二进制搜索树-有序遍历

[英]Binary Search Tree - In-order Traversal

I am trying to make a crossword puzzle program utilizing BST's, i currently have the following words inserted into the tree: 我正在尝试使用BST制作填字游戏,我目前在树中插入了以下单词:

word, will, wyr, wale, wilt, apple, abs, wack(inserted in that order) 单词,威尔,威尔,威尔士,枯萎,苹果,abs,古怪(按此顺序插入)

but everytime i debug the program in visual studio, i get an error 但是每次我在Visual Studio中调试程序时,都会出现错误

Exception thrown at 0x008DE28C in AVLBSTcrosswordhunter.exe: 0xC0000005: Access violation writing location 0x0000001C.

However, when tracing the variables my traversed variable is never set to 1, so i do not exit this while loop, the error is happening inside, im just not sure where and why. 但是,当跟踪变量时,我遍历的变量永远不会设置为1,因此我不会在while循环中退出,错误发生在内部,我只是不确定在哪里以及为什么。

while (!traversed)
{
    if (temp != NULL)
    {
        if (temp->word.substr(0, sub_num) == value.substr(0, sub_num))
        {
            count++;
        }
        s.push(temp);
        temp = temp->left;
    }
    else
    {
        if (!s.empty())
        {
            temp = s.top();
            s.pop();
            temp = temp->right;
        }
        if (s.empty())
        {
            traversed = 1;
        }
    }
}

for clarification, the word i'm searching for is "w***"(the '*' being wildcards), so the if statement checks to see if the pointer temp has the substring w, and if sound it increases count so i can send a number back on how many match that wildcard search. 为了清楚起见,我要搜索的单词是“ w ***”(“ *”是通配符),因此if语句检查指针temp是否具有子字符串w,如果声音则增加计数,所以我可以传回与该通配符搜索匹配的数字。

Also, temp is set to the root(word) before the while loop. 另外,在while循环之前,将temp设置为根(字)。

Thank you for any help that you can provide! 感谢您提供的任何帮助!

看来我匆忙完成此操作时创建了两个遍历变量和两个堆栈变量,现在看来可以正常工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM