i'm trying to insert and element in a list in alphabetical order last name first and then first name here is my code but not working please help
struct node * Inserting(struct node *tp,struct node *fp)
{
struct node *last = NULL;
struct node *old, *start;
start = fp;
if(!last)
{
tp->nextptr = NULL;
last = tp;
return tp;
}
old = NULL;
while(fp)
{
if(strcmp(fp->lastname,tp->lastname) < 0)
{
old = fp;
fp = fp->nextptr;
}
else
{
if (old)
{
old->nextptr = tp;
tp->nextptr = fp;
return start;
}
tp->nextptr = fp;
return tp;
}
}
last->nextptr = tp;
tp->nextptr = NULL;
last = tp;
return start;
Code tags added. -Narue