BST insert method seems to be crashing my prog
Hi, i am pretty damned sure i wrote the code for this insert method correctly (maybe not 100%) , but the program crashes when the first word is inserted into the Tree.
insert method being called...
Code:
while( inputFile >> word )
{
word += " "; // append space to each word before displaying
// next character is newline?
if( inputFile.peek() == '\n' || inputFile.peek() == '\r' )
word += "\r\n"; // append a 'windows' newline
textDataDisplay->AppendText( word.c_str() );
// remove punctuation from each word
removePunctFrom( word );
bsTree->insertNode( word.c_str() );// insert word into BST
}
insert code...
Code:
void insertNode( String* data )
{
Node* currentNode = EMPTY_NODE; // stores current node
if( treeRoot->isEmpty() ) // is tree empty?
treeRoot = new Node( data ); // add data as root
else // tree is not empty
{
// see if a node with this data already exists
currentNode = findNode( data, false );
// test for duplicate data in tree
if( currentNode->isEmpty() )
{
currentNode = treeRoot;
// traverse tree until we reach an empty node
while( !currentNode->isEmpty() )
{
// data to insert is < data of currentNode
if( data->CompareTo( currentNode->data() ) < 0 )
{
currentNode = currentNode->leftChild();
}
else // data to insert is > data of currentNode
{
currentNode = currentNode->rightChild();
}
}
// store the data in the empty node
currentNode = new Node( data );
}
else // a matching node was found
{
errorState = BAD_STATE; // set the state to bad
return; // return from this function
}
}
errorState = GOOD_STATE; // operation was successful
}// insertNode
Any help is GREATLY appreciated, my head is literally hurting me trying to figure out the problem