Initializtion

This commit is contained in:
Kozar 2024-04-25 21:23:56 +02:00
parent e58d893b96
commit 8876568a45

View File

@ -30,30 +30,3 @@ node_t *build_tree(int *tree_data, size_t tree_data_len) {
}
return tree;
}
void free_tree(node_t *tree) {
if (tree == NULL) {
return;
}
free_tree(tree->left);
free_tree(tree->right);
free(tree);
}
void in_order_traversal(node_t *tree, int *sorted_data, int *index) {
if (tree == NULL) {
return;
}
in_order_traversal(tree->left, sorted_data, index);
sorted_data[(*index)++] = tree->data;
in_order_traversal(tree->right, sorted_data, index);
}
int *sorted_data(node_t *tree, size_t tree_data_len) {
int *sorted_data = (int *)malloc(tree_data_len * sizeof(int));
int index = 0;
in_order_traversal(tree, sorted_data, &index);
return sorted_data;
}