I am trying to find a name within a key. I think it is retrieving it fine. however, its coming up as not found. maybe my code is wrong somewhere?
if (database.retrieve(name, aData)) // both contain the match
in main()
static void retrieveItem(char *name, data& aData)
{
cout << ">>> retrieve " << name << endl << endl;
if (database.retrieve(name, aData)) // name and aData both contain the match
cout << aData << endl;
else
cout << "not found\n";
cout << endl;
}
static void removeItem(char *name)
{
cout << ">>> remove " << name << endl << endl;
if (database.remove(name))
cout << name << " removed\n";
else
cout << name << " not found\n";
cout << endl;
}
int main()
{
#ifdef _WIN32
// request memory leak report in Output Window after main returns
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
data aData;
<< "Database Of Great Computer Scientists\n\n";
database.insert(data("Ralston, Anthony"));
database.insert(data("Liang, Li"));
database.insert(data("Jones, Doug"));
database.insert(data("Goble, Colin"));
database.insert(data("Knuth, Donald"));
database.insert(data("Kay, Alan"));
database.insert(data("Von Neumann, John"));
database.insert(data("Trigoboff, Michael"));
database.insert(data("Turing, Alan"));
displayDatabase(true);
retrieveItem("Trigoboff, Michael", aData);
retrieveItem("Kaye, Danny", aData);
removeItem("Ralston, Anthony");
displayDatabase(true);
retrieve function...
bool BST::retrieve(const char *key, data &aData, int parent) const
{
for(int index=0; index < maxsize+1; index++)
{
if (!items[index].empty)
{
if ( items[index].instanceData == key )
{
aData.setName(key);
return true; // doesn't return right away
}
}
}
}
and defined in data.cpp
bool operator== (const data& d1, const data& d2)
{
return strcmp(d1.getName(), d2.getName()) == 0;
}
so this bit of code inside main() is where it says not found when i think it should be working correctly. both name and aData contain the right name that was found..
static void retrieveItem(char *name, data& aData)
{
cout << ">>> retrieve " << name << endl << endl;
if (database.retrieve(name, aData)) // name and aData both contain the match
cout << aData << endl;
else
cout << "not found\n";
cout << endl;
}