From e40b7d33adb6cb918eb30951391e8b74f992b4e0 Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Tue, 23 Apr 2024 19:55:17 +0200 Subject: [PATCH] rewrwrewr --- a3/binary_search_tree.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/a3/binary_search_tree.c b/a3/binary_search_tree.c index 5528fa4..033d628 100644 --- a/a3/binary_search_tree.c +++ b/a3/binary_search_tree.c @@ -40,16 +40,16 @@ int *sorted_data(node_t *tree) { stack[stack_top++] = tree; tree = tree->left; } - - tree = stack[--stack_top]; - sorted_array[index++] = tree->data; - tree = tree->right; + if (stack_top > 0) { + tree = stack[--stack_top]; + sorted_array[index++] = tree->data; + tree = tree->right; + } } return sorted_array; } - node_t *build_tree(int *tree_data, size_t tree_data_len) { if (tree_data == NULL || tree_data_len == 0) { return NULL;