To delete a tree we must traverse all the nodes of the tree and delete them one by one. So which traversal we should use – Inorder or Preorder or Postorder. Answer is simple – Postorder, because before deleting the parent node we should delete its children nodes first
Read full article from Write a C program to Delete a Tree. | GeeksforGeeks
void
deleteTree(
struct
node* node)
{
if
(node == NULL)
return
;
/* first delete both subtrees */
deleteTree(node->left);
deleteTree(node->right);
/* then delete the node */
printf
(
"\n Deleting node: %d"
, node->data);
free
(node);
}