summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-07-11 16:55:53 -0600
committermo khan <mo.khan@gmail.com>2020-07-11 16:55:53 -0600
commit75941ee7c57805f931a2fd1e40b2d109c7ac30de (patch)
tree91917287a566609892a92b8f2526582be1413441 /src
parentb9d31fde299fd7b40f3bcd4aae456a31ea4ce87d (diff)
Free memory for binary tree in postorder
Diffstat (limited to 'src')
-rw-r--r--src/02/01/binary_tree.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/02/01/binary_tree.c b/src/02/01/binary_tree.c
index 7fd9763..00abae5 100644
--- a/src/02/01/binary_tree.c
+++ b/src/02/01/binary_tree.c
@@ -27,6 +27,10 @@ void postorder_traversal(Node *node, Visitor visitor) {
visitor(node);
}
+static void destructor(Node *node) {
+ free(node);
+}
+
void destroy(Node *head) {
- free(head);
+ postorder_traversal(head, destructor);
}