diff --git a/a3/binary_search_tree.c b/a3/binary_search_tree.c index 87eab08..2ccc411 100644 --- a/a3/binary_search_tree.c +++ b/a3/binary_search_tree.c @@ -13,6 +13,29 @@ void free_tree(node_t *tree) { free(tree); } +int *sorted_data(node_t *tree) { + if (tree == NULL) { + return NULL; + } + + size_t num_nodes = 0; + node_t *current = tree; + while (current != NULL) { + num_nodes++; + current = current->right; + } + + int *sorted_array = (int *)malloc(num_nodes * sizeof(int)); + if (sorted_array == NULL) { + return NULL; + } + + size_t index = 0; + + inorder_traversal(tree, sorted_array, &index); + + return sorted_array; +} node_t *build_tree(int *tree_data, size_t tree_data_len){