From a38b9a5579fccd2a70836e54ef461bb64a7bc9fe Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Tue, 23 Apr 2024 19:47:38 +0200 Subject: [PATCH] sksuak 34843924234242 --- a3/binary_search_tree.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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){