Skip to content

Instantly share code, notes, and snippets.

@allisons
Created August 9, 2010 23:25
Show Gist options
  • Save allisons/516318 to your computer and use it in GitHub Desktop.
Save allisons/516318 to your computer and use it in GitHub Desktop.
bool BST::retrieve(const char *key, data& aData)
{
int node = 0;
aData = items[retrievePrivate(key, node)].theData;
if (aData.getName() != NULL)
return true;
return false;
}
int BST::retrievePrivate(const char * key, int node)
{
if(items[node].theData.getName() == NULL)
{
return 600;
}
if(strcmp(items[node].theData.getName(), key) == 0)
{
cout << "Found " << key << " at " << node << endl;
return node;
}
cout << "Not found at " << node << endl;
if(strcmp(items[node].theData.getName(), key) > 0)
{
cout << "Checking the left child" << endl;
retrievePrivate(key, leftChild(node));
}
if(strcmp(items[node].theData.getName(), key) < 0)
{
cout << "Checking the right child" << endl;
retrievePrivate(key, rightChild(node));
}
return node;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment