Hero is a code fragment from our singlylinked list example f
Hero is a code fragment, from our singly-linked list example from class./* DEALLOCATE LIST */for (current_cell = head; current_ce11 != NULL; current_cell = current_cell->next) free(current_cell); Is there a safety issue with this code? Explain. How can you rewrite this code lo make it safe? You can introduce new variables, if needed.
Solution
Hi Please find my answer.
1)
Yes, we are deleteing first : free(current_cell), before forwarding to next node.
2)
current_cell = head;
while(current_cell != NULL){
temp = current_cell; // temp is of type node
current_cell = current_cell->next;
free(temp);
}
head = NULL;
