Created
August 9, 2010 23:25
-
-
Save allisons/516318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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