Initializtion
This commit is contained in:
parent
a171e83985
commit
a2f279f2e3
@ -1,5 +1,6 @@
|
||||
#include "binary_search_tree.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
node_t *build_tree(int *tree_data, size_t tree_data_len) {
|
||||
if (tree_data_len == 0) {
|
||||
@ -50,24 +51,8 @@ void free_tree(node_t *tree) {
|
||||
}
|
||||
|
||||
int *sorted_data(node_t *tree) {
|
||||
int *data = NULL;
|
||||
size_t data_len = 0;
|
||||
|
||||
void in_order_traversal(node_t *node) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
in_order_traversal(node->left);
|
||||
|
||||
data = realloc(data, (data_len + 1) * sizeof(int));
|
||||
data[data_len] = node->data;
|
||||
data_len++;
|
||||
|
||||
in_order_traversal(node->right);
|
||||
}
|
||||
|
||||
in_order_traversal(tree);
|
||||
|
||||
int *data = malloc(sizeof(int) * count_nodes(tree));
|
||||
int *ptr = data;
|
||||
in_order_traversal(tree, &ptr);
|
||||
return data;
|
||||
}
|
Loading…
Reference in New Issue
Block a user