w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Binary search Tree Seg faults when doing a tree walk after removing its root

The reason the print function would seg fault was because when i called delete on that certain pointer it would delete EVERYTHING underneath it. my solution was: [thanks again john]

void BST::remove(string key, string data)
{
    Node* ptr = m_root;
    Node* tmp = TREE_SEARCH(ptr, key);
    while(tmp != NULL)
    {
        if(tmp->m_data == data)
        {
            TREE_DELETE(tmp);
            tmp->m_parent = NULL;
            tmp->m_right = NULL;
            tmp->m_left = NULL;
            delete tmp;
            return;
        }
        else
        {
            tmp = tmp->m_right;
        }
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.