简体   繁体   中英

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:

word, will, wyr, wale, wilt, apple, abs, wack(inserted in that order)

but everytime i debug the program in visual studio, i get an error

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.

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.

Also, temp is set to the root(word) before the while loop.

Thank you for any help that you can provide!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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