I have a method that is suppose to return a garbage value if an item in a tree is not found. All I'm getting though is a runtime exception: "garbage is being used without being defined"
ItemType BstClass::rRetrieve(node* trav, KeyType key, bool& inTree)
{
if(trav == NULL)
{
inTree = false;
ItemType garbage;
return garbage - 1;
}
if(trav->data.key == key)
{
inTree = true;
return trav->data;
}
else if (key < trav->data.key)
return(rRetrieve(trav->left, key, inTree));
else
return(rRetrieve(trav->right, key, inTree));
}// end rRetrieve
Is there another way to do this? We were told to use
return garbage - 1;