vendredi 10 septembre 2021

Why is the following C code not returning 0 after the linked list is free'd from memory?

This function is supposed to delete linked list in C only if it is empty. The ll_length() function is confirmed working. If the linked list is successfully deleted, we are to return 0. If it is not deleted, return negative one. This program is returning -1. It enters the first if statement but not the second. What is wrong

ll_destroy(struct linked_list *ll)
{
  if (ll_length(ll) == 0){
    free(ll);
    if (ll == NULL){
      return 0; //remove 0 if removed   
     }
  }
  return -1; // if not deleted
}

Aucun commentaire:

Enregistrer un commentaire