Question: Task 4 : Destroy the Tree: destroy During add _ node ( ) we malloc ( ) ' ed a lot, so before exiting our

Task 4: Destroy the Tree: destroy
During add_node() we malloc()'ed a lot, so before exiting our program we need to free those spaces on
the heap by calling destroy() :
1 void destroy(tree_t*);
where tree_t* argument is the pointer to the tree. One thing to pay attention to is how many malloc() we
used in add_node(), then we should free() same amount of time. Also, for each node, what's the order of
multiple free()'s?
Again, it'll be easier to do that in recursion. You are free to create helper functions.
Note
We will emphasize this again: because this is a generic BST, you must not use if-else to discriminate different
data types in your code. For example, the following is not allowed:
if sizeof data
Please write in C
 Task 4: Destroy the Tree: destroy During add_node() we malloc()'ed a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!