Am încercat să găsească un nume într-o cheie. Cred că este bine că recuperarea. Cu toate acestea, ei venind ca nu a fost găsit. Poate codul meu este greșit undeva?
if (database.retrieve(name, aData)) // both contain the match
în 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);
funcția de a prelua ...
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
}
}
}
}
și definite în data.cpp
bool operator== (const data& d1, const data& d2)
{
return strcmp(d1.getName(), d2.getName()) == 0;
}
astfel încât acest bit de cod interior principal () este în cazul în care nu spune găsit atunci când cred că ar trebui să funcționeze corect. atât numele și ADATA conțin numele dreapta care a fost găsit ..
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;
}













