Linked list search problems

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Closed Thread

Join Date: Nov 2006
Posts: 16
Reputation: sbenware is an unknown quantity at this point 
Solved Threads: 0
sbenware's Avatar
sbenware sbenware is offline Offline
Newbie Poster

Linked list search problems

 
0
  #1
Mar 19th, 2007
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;
}
Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Linked list search problems

 
0
  #2
Mar 19th, 2007
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.
Quick reply to this message  
Join Date: Nov 2006
Posts: 16
Reputation: sbenware is an unknown quantity at this point 
Solved Threads: 0
sbenware's Avatar
sbenware sbenware is offline Offline
Newbie Poster

Re: Linked list search problems

 
0
  #3
Mar 19th, 2007
Sorry. I didn't know how to delete this post after i noticed I was in the wrong forum.
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC