#include #include #include #include #include "binary_search_tree.h" #include node_t *create_node(int data) ; node_t *create_node(int data) { node_t *new_node = (node_t *)malloc(sizeof(node_t)); new_node->data = data; new_node->left = NULL; new_node->right = NULL; return new_node; } node_t *build_tree(int *tree_data, size_t tree_data_len) { node_t *root = create_node(tree_data[0]); size_t i = 1; while (i < tree_data_len) { node_t *new_node = create_node(tree_data[i]); node_t *current = root; while (1) { if (new_node->data <= current->data) { //porovnanie novy uzol a aktualny if (current->left == NULL) { current->left = new_node; break; } current = current->left; } else { if (current->right == NULL) { current->right = new_node; break; } current = current->right; } } i++; } return root; } // Function to free the memory allocated for the binary search tree void free_tree(node_t *tree) { free(tree); } // Function to return sorted data from the binary search tree int *sorted_data(node_t *tree) { if(tree==NULL){ return NULL; } return NULL; }