What is the difference between these programs? I am studying for an exam and I think the 2nd one is easier to follow, its recursive I know that...
Code:
void ResetList(struct point **ptrFirst, struct point **ptrLast) {
struct point *current = *ptrFirst;
struct point *next = NULL;
// free up all the memory in the list
while (current != NULL) {
next = current->ptrNext;
free(current);
current = next;
}
// update the first and last pointers, which still point to the freed memory
*ptrFirst = NULL;
*ptrLast = NULL;
}
Code:
// user must clear ptrFirst and ptrLast
void ClearList(struct node * ptrF)
{
// base case: empty list
if (ptrF == NULL)
return;
else
{
ClearList(ptrF->ptrNext);
free(ptrF);
}
}