I need to make a parametrized constructor that creates a perfectly balanced binary search tree given a sorted array. I know how to make a function that creates the BST but how can I make the BST from a constructor? This is my function:
node * sortedArrayBST(double * arr, int start, int end)
{
int mid = (start + end)/2;
if (start > end)
{
return NULL;
}
//because the array will be sorted
//the root of the tree will contain the item in the middle of the array so everything less than the middle will go in the left subtree
//and everything greater than the middle will go in the right subtree
node * root = new node(arr[mid]);
//recursively make left subtree
root->left = sortedArrayBST(arr, start, end-1);
//recursively make left subtree
root->right = sortedArrayBST(arr, mid + 1, end);
return root;
}