LinkedList - How to free the memory allocated using malloc

后端 未结 5 601
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 20:53

I have a very simple C code for constructing a Singly Linked list as below, in which I allocate memory for each node dynamically using malloc. At the end of code, I want to

5条回答
  •  独厮守ぢ
    2020-12-23 21:25

    You traverse the list using the same logic as above. You save the curr->next pointer somewhere, free the curr struct and assign curr with the saved curr->next pointer

提交回复
热议问题