diff --git a/a3/binary_search_tree.c b/a3/binary_search_tree.c index acd2e21..3a28213 100644 --- a/a3/binary_search_tree.c +++ b/a3/binary_search_tree.c @@ -1,11 +1,5 @@ -#include #include "binary_search_tree.h" - -typedef struct node { - struct node *right; - struct node *left; - int data; -} node_t; +#include node_t* insert(node_t *node, int data) { if (node == NULL) { @@ -22,6 +16,13 @@ node_t* insert(node_t *node, int data) { } } +void inorder_traversal(node_t *node, int *sorted) { + if (node == NULL) return; + inorder_traversal(node->left, sorted); + sorted[sorted_index++] = node->data; + inorder_traversal(node->right, sorted); +} + node_t* build_tree(int *tree_data, size_t tree_data_len) { node_t *root = NULL; for (size_t i = 0; i < tree_data_len; i++) { @@ -37,15 +38,6 @@ void free_tree(node_t *tree) { free(tree); } -static int sorted_index = 0; - -void inorder_traversal(node_t *node, int *sorted) { - if (node == NULL) return; - inorder_traversal(node->left, sorted); - sorted[sorted_index++] = node->data; - inorder_traversal(node->right, sorted); -} - int *sorted_data(node_t *tree) { int *sorted = (int*)malloc(sizeof(int) * 1000); // Předpokládáme, že strom má maximálně 1000 prvků sorted_index = 0;