#Avoid using recursive function calls in c (or similar languages)
Avoid using recursive function calls in c (or similar languages)
#Fix your indentation and always use a clear scope
Fix your indentation and always use a clear scope
#Avoid using recursive function calls in c (or similar languages)
#Fix your indentation and always use a clear scope
Avoid using recursive function calls in c (or similar languages)
Fix your indentation and always use a clear scope
Tree BuildTreeFromArray(int *arr, int size) { // ... if (size == 1) { // ... } else { halfSize = size / 2; resTree.root->data = arr[halfSize]; // !!! Should be indented according the enclosing scope block
// ... if (arr[halfSize/2] != -1) {//we check if there's a valid array data we can input to the tree // ... } else // !!! Missing scope block resTree.root->left = NULL; if (arr[halfSize + (halfSize / 2) + 1] != -1) { // ... } else // !!! Missing scope block resTree.root->right = NULL; } return resTree; }
Tree BuildTreeFromArray(int *arr, int size) { // ... if (size == 1) { // ... } else { halfSize = size / 2; resTree.root->data = arr[halfSize]; // !!! Should be indented according the enclosing scope block
if (arr[halfSize/2] != -1) {//we check if there's a valid array data we can input to the tree // ... } else // !!! Missing scope block resTree.root->left = NULL; if (arr[halfSize + (halfSize / 2) + 1] != -1) { // ... } else // !!! Missing scope block resTree.root->right = NULL; } return resTree; }
Tree BuildTreeFromArray(int *arr, int size) { // ... if (size == 1) { // ... } else { halfSize = size / 2; resTree.root->data = arr[halfSize]; // !!! Should be indented according the enclosing scope block // ... if (arr[halfSize/2] != -1) {//we check if there's a valid array data we can input to the tree // ... } else // !!! Missing scope block resTree.root->left = NULL; if (arr[halfSize + (halfSize / 2) + 1] != -1) { // ... } else // !!! Missing scope block resTree.root->right = NULL; } return resTree; }
Here's the fully fixed version (I'm not sure that will provide exactly the same logic as you currently havhave it):
Here's the fully fixed version (I'm not sure that will provide exactly the same logic as you currently hav it):
Here's the fully fixed version (I'm not sure that will provide exactly the same logic as you currently have it):