diff --git a/a3/binary_search_tree.c b/a3/binary_search_tree.c index 0114dce..536dc91 100644 --- a/a3/binary_search_tree.c +++ b/a3/binary_search_tree.c @@ -2,6 +2,9 @@ #include #include +int count_nodes(node_t *tree); +void in_order_traversal(node_t *tree, int **ptr); + node_t *build_tree(int *tree_data, size_t tree_data_len) { if (tree_data_len == 0) { return NULL; @@ -56,3 +59,22 @@ int *sorted_data(node_t *tree) { in_order_traversal(tree, &ptr); return data; } + +int count_nodes(node_t *tree) { + if (tree == NULL) { + return 0; + } + + return 1 + count_nodes(tree->left) + count_nodes(tree->right); +} + +void in_order_traversal(node_t *tree, int **ptr) { + if (tree == NULL) { + return; + } + + in_order_traversal(tree->left, ptr); + **ptr = tree->data; + (*ptr)++; + in_order_traversal(tree->right, ptr); +} \ No newline at end of file