rwererewrw

This commit is contained in:
Michal Utľák 2024-04-23 19:51:08 +02:00
parent 6eef05da23
commit 2a72097c20

View File

@ -59,17 +59,21 @@ int *sorted_data(node_t *tree) {
} }
node_t *build_tree(int *tree_data, size_t tree_data_len) { node_t *build_tree(int *tree_data, size_t tree_data_len) {
node_t *koren = (node_t *)malloc(sizeof(node_t));
if (tree_data == NULL || tree_data_len == 0) { if (tree_data == NULL || tree_data_len == 0) {
return 0; return NULL;
}
node_t *koren = (node_t *)malloc(sizeof(node_t));
if (koren == NULL) {
return NULL;
} }
if(tree_data != NULL && tree_data_len != 0){
koren->data = tree_data[0]; koren->data = tree_data[0];
koren->left = (node_t *)malloc(sizeof(node_t)); koren->left = NULL;
koren->left->data = tree_data[0]; koren->right = NULL;
if (tree_data_len > 1) {
koren->left = build_tree(tree_data + 1, tree_data_len - 1);
} }
return koren; return koren;