Hey can anyone tell me whats wrong with my code? I'm getting a program freeze.
http://i47.tinypic.com/wh1ez5.png

I'm doing a binary search tree,
BST.CPP
http://pastebin.org/57667

Person.CPP
http://pastebin.org/57669

TreeNode.CPP
http://pastebin.org/57670

Main---Where I call the searchTreeInsert function
http://pastebin.org/57674

Recommended Answers

All 3 Replies

you are probably reading/writing a invalid memory.

you are probably reading/writing a invalid memory.

usually the program just crash, not stop.

.hpp missing, to test it local, can you provide them?

btw, just a hint:

void BinarySTree::copyTree(TreeNode* treePtr, TreeNode* newTreePtr){
    if (treePtr!=NULL){
        newTreePtr == new TreeNode(treePtr->item, NULL, NULL);


        // newTreePtr == new(std::nothrow) TreeNode(treePtr->item, NULL, NULL);
        // newTreePtr -> no memory -> newTreePtr will be NULL
        
        // this will NOT happen!
        // new will throw bad_alloc
        if (newTreePtr ==NULL)
            cout<<"Cannot allocatememory";
        copyTree(treePtr->leftChildPointer, newTreePtr->leftChildPointer);
        copyTree(treePtr->rightChildPointer, newTreePtr->rightChildPointer);
    }else{
        newTreePtr = NULL; //copyEmptyTree
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.