Q:
I don't get an error when I compile, but I get one when I try to add a
record in this function, It has to be a recursive insert function...Can
you tell what I might be doing wrong?
void InsertItem(nodeptr *pList, nodeptr newptr)
{
nodeptr prevptr = *pList;
if(*pList != NULL && newptr->data.empID < (*pList)->data.empID)
{
prevptr = *pList;
*pList = (*pList)->link;
InsertItem(pList, newptr);
}
else
{
prevptr->link = newptr;
newptr->link = *pList;
}
}
A:
What happens, when *pList is NULL? In this case prevptr is NULL and
prevptr->link is core dump in the 'else' branch.
Regards,
Peter
[ back to toc ]