I want to convert sorted 1-D array to Binary Search Tree, but I am not getting the desired output with this code:
int arr[7] = {-10,-3,-1,0,3,7,9};
typedef struct tree{
int data;
struct tree *left;
struct tree *right;
}bst;
struct tree *CreateNode(int data){
bst *node = (bst*)malloc(sizeof(bst));
node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
struct tree *BST(bst *root,int start,int end){
if(start>end){
return NULL;
}
int mid = start + (end-start)/2;
root = CreateNode(arr[mid]);
BST(root->left,start,mid-1);
// printf("%d\n",root->data);
BST(root->right,mid+1,end);
return root;
}