Learn basic concept of c , c++ and python programming in regularcodes.com
delete all nodes in linked list
Before end of program execution delete all linked list node. because the best way to utilize heap memory are allocation and deallocation.
1) Overcome of memory leak problem.
2) Efficiently use dynamic memory allocation on heap.
Most of tool are detect memory leak of your program. Valgrind is one of the popular tool to detect memory leak.
let us discuss about how to delete linked list node.
Given a Linked list.
In this linked list 8 nodes. view insertion process.
Algorithm to delete node:
Use one temp pointer.
step 1: Assign the temp pointer value is root node value.
step 2: move root to next memory block and free temp pointer.
continue this steps when root is not NULL.
Use free() function to delete linked linked list node. this function takes address of delete node.
c program to delete all nodes of given linked list.
Code execution: view code execution process.
Note that not given all step of execution process here. view more.