sksuak 34843924234242

This commit is contained in:
Michal Utľák 2024-04-23 19:47:38 +02:00
parent 307b3b5b3d
commit a38b9a5579

View File

@ -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){