So I am sure this is super easy and I am just missing it but I need to make an unsorted array to BST. I have an array int [] data = { 50, 30, 60, 10, 80, 55, 40 }; and I need to convert it to an unbalanced BST with the first number as the root no matter what I change it to and the other numbers follow the left and right rules. I have this code which works for this array but not if i changed the number to something not in the middle.
public Node arraytoBinary(int [] array, int start, int end) {
if (start > end){
return null;
}
int mid = (start + end) / 2;
Node node = new Node(array[mid]);
node.left = arraytoBinary(array, start, mid - 1);
node.right = arraytoBinary(array, mid + 1, end);
return node;
}