This commit is contained in:
Macko 2024-04-18 15:20:29 +02:00
parent b955cf1824
commit 0cd0b96b00

View File

@ -1,11 +1,5 @@
#include <stdlib.h>
#include "binary_search_tree.h"
typedef struct node {
struct node *right;
struct node *left;
int data;
} node_t;
#include <stdlib.h>
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;