| | |
Linked list search problems
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
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;
}
--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
- help implementing singly linked list (C++)
- adding and deleting node in a linked list (C++)
- ordered linked list (C)
- doubly linked list--- help needed1 (C++)
- more linked list printing problems (C)
- To create contact manager using doubly linked list(c++) (C++)
- Linked List (C++)
Other Threads in the Computer Science Forum
- Previous Thread: Time Complexity ?
- Next Thread: SAS/Oracle Date Problem
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business codebreaker compiler computer computers computerscience computertrackingsoftware connect conversion csc dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis dissertationtopic ebook employment energy floatingpoint foreclosure foreclosuresoftware gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet iphone ipod itcontracts jobs kindle laser laws linkbait lsmeans mainframes marketing mobileapplication msaccess nano netbeans networking news os p2p piracy piratebay principles programming rasterizer research sam-being-cute sas science security sex simulation software spying stephenfry study supercomputer supercomputing sweden technology textfield turing two'scompliment uk virus ww2





