Hey guys,
I have a compare function which receives at different times either first name, last name and maybe even both? Initially when wrote my lab it was only for the first name..how do I modify the code to accomodate for both first name or last name..(first name and last name are fields in the KEY structure of a linked list)..any ideas?
strcture KEY contains an array for first names and another array for last names..
This was my initial code..how do I modify it?
Code:
int cmp(KEY k, KEY k2)
{
int cmp = 0;
cmp = strcmp(k.names, k2.names);
return cmp;
}
and this is my search function that gets first name OR last name OR both..
Code:
int searchList(NODE *pList,
NODE **pCur,
NODE **pPre,
KEY k)
{
int found = 0;
// initialize
*pPre = NULL;
*pCur = pList;
//Start search
while(*pCur != NULL && (cmp(k, (*pCur)->directory.k) > 0))
{
*pPre = *pCur;
*pCur = (*pCur)-> next;
}
if(*pCur && (cmp(k, (*pCur)->directory.k) == 0))
{
found = 1;
}
return found;
}
Currently, this search function works just fine if I want to look up the directory using first names..need to modify it so that I can search using last names as well. Any ideas?
The main idea behind the code is that it should be generic. Thats what the purpose of the project is: to recycle code..
Thanks
A