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;