944,081 Members | Top Members by Rank

Ad:
Mar 19th, 2007
0

Linked list search problems

Expand Post »
I'm having a problem with my search function for my linked list. It has to do with my foodItem object. I'm not sure what to replace it with since it's part of the function protocol. The previous version of this code used an array and part of my problem is correctly converting to a linked list format. I'm really stuck, so any advice would be much appreciated. I hope I didn't leave out anything helpful. --Sheila

[code]
/**
*searchByName:search for foods by name
*in:name
*out:foodItem
*return:true if there is a match, or else false
**/
bool FoodList::searchByName(char name[],Food& foodItem)const
{
int i;
size = foodItem.size;
Node * current;
if(foodItem.head == NULL)
head = NULL;
else
{
for(current=head;current;current=current->next)
{
if(strcmp(head->data.name,name) == 0)
{
strcpy(head->data.name,foodItem.head->data.name);
head->data.category = foodItem.head->data.category;
head->data.calories = foodItem.head->data.calories;
head->data.carbohydrates = foodItem.head->data.carbohydrates;
head->data.fat = foodItem.head->data.fat;
head->data.cholesterol = foodItem.head->data.cholesterol;
head->data.sodium = foodItem.head->data.sodium;
head->data.protein = foodItem.head->data.protein;
return true;
}
else{
}
return false;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sbenware is offline Offline
16 posts
since Nov 2006
Mar 19th, 2007
0

Re: Linked list search problems

This thread has a duplicate in the C++ forum. I suggest this one be closed, if a mod would be so inclined. Please don't double-post in the future.
Reputation Points: 683
Solved Threads: 53
Posting Virtuoso
Infarction is offline Offline
1,580 posts
since May 2006
Mar 19th, 2007
0

Re: Linked list search problems

Sorry. I didn't know how to delete this post after i noticed I was in the wrong forum.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sbenware is offline Offline
16 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Computer Science Forum Timeline: Time Complexity ?
Next Thread in Computer Science Forum Timeline: SAS/Oracle Date Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC