I need to create a search function that search for a product type. If it's found, I return true, otherwise i return false. My client program will output the data that was found (if true), otherwise it'll output an error message saying that product type does not exist in the data base.
Teachers notes:
* you might need to return more than one vendor
* you can make the client program to pass in an array (adata) and populate this array in the retrieve function
I'm using a hash table.. So basically this function brings in the key (which is the product type) from the users input. And we are passing in our data as well as a pointer.
Now, for some reason when I run my program, and I search for an item with only one unique product type, I don't get an error. But as soon as a search for a product type that many items have, then I get an error. Someone pls help me out, this is do soon and I'm really lost.
bool BST::retrieve(char * key, data * aData)const
{
//calculate the retrieval position using hash function (getIndex)
int i = getIndex(key); //Hash Function
int j = 0;
//search for the data in the chain (linked list)
hashNode * curr = table[i];
char productType[100];
while(curr)
{
curr->item.getProductType(productType);
if(strcmp(key, productType) == 0)
{
// Product type exists so populate array
aData[j] = curr->item;
curr = curr->next;
j++;
}
else
curr = curr->next;
}
if(j > 0)
return true;
else
return false;
}