Write a function DeleteList() that takes a list, deallocates all of its memory and sets its head pointer to NULL (the empty list).
void DeleteList(struct node** headRef)
{
struct node* current = *headRef; // deref headRef to get the real head
struct node* next;
while (current != NULL)
{
next = current->next; // note the next pointer
free(current); // delete the node
current = next; // advance to the next node
}
*headRef = NULL; // Again, deref headRef to affect the real head back
// in the caller.
}
{
struct node* current = *headRef; // deref headRef to get the real head
struct node* next;
while (current != NULL)
{
next = current->next; // note the next pointer
free(current); // delete the node
current = next; // advance to the next node
}
*headRef = NULL; // Again, deref headRef to affect the real head back
// in the caller.
}
8:58 AM |
Category: |
1 comments
Comments (1)
jkj
jkj
jk
kjkjkj