I am using a binary tree whereby the search item is return using pass by reference i.e. "searchElement" store the result
Code:
int BSTree::retrieve ( String searchKey, Car *searchElement )
{
return ( retrieveSub (root, searchKey, searchElement));
}
//recursion partner fucntion of retrieve
int BSTree::retrieveSub ( BSTreeNode *ptr, String key, Car *element )
{
if ( ptr == 0 )
return 0;
else if ( key < ptr->element.key() )
return retrieveSub (ptr->left, key, element);
else if ( key > ptr->element.key() )
return retrieveSub (ptr->right, key, element);
else
{
//at this point, the item address is correctly assign to element
//however, when return to the retrieve function, the searchElement is NULL
element = &ptr->element;
return 1;
}
}
During debugging, the watch value of element is correct, but when return to parent function, the searchElement is NULL. (both element and searchElement should point to the same address.) What am I missing here? Thanks