Code running good but test case not passing. Please help!

import java.util.Scanner;
public class Main
{
public static class BST
{
private class Node
{
private int data;
private Node left;
private Node right;
}

	private Node root;
	
	BST(int []arr)
	{
		this.root=construct(arr,0,arr.length-1);
	}
	
	private Node construct(int []a, int low,int high)
	{
		if(low>high)
			return null;
		int mid=(low+high)/2;
		Node nn=new Node();
		nn.data=a[mid];
	
		nn.left=this.construct(a,low,mid-1);
		nn.right=this.construct(a,mid+1,high);			

		return nn;
	}

    	public void preOrder()
	{
		preOrder(root);
	}
	private void preOrder(Node node)
	{
		if(node==null)
			return;
		System.out.print(node.data+" ");
		preOrder(node.left);
		preOrder(node.right);
	}
	
	public void range(int beg,int end)
	{
		range(root,beg,end);
	}
	private void range(Node node,int beg,int end)
	{
		if(node==null)
			return;
		range(node.left,beg,end);
		if(node.data>=beg && node.data<=end)
		System.out.print(node.data+" ");
		range(node.right,beg,end);
	}
}

public static void sort(int []a)
{
    int small,pos;
    for(int i=0;i<a.length-1;i++)
    {
        small=a[i];
        pos=i;
        for(int j=i+1;j<a.length;j++)
        {
           if(a[j]<small) 
           {small=a[j];
           pos=j;
               break;
           }
        }
        int save=a[i];
        a[i]=small;
        a[pos]=save;
    }
}

public static void main(String[] args) 
{
    Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t>0)
	{
	    int n=sc.nextInt();
	    int a[]=new int[n];
	    for(int i=0;i<n;i++)
	    {
	        a[i]=sc.nextInt();
	    }
	    sort(a);
	    BST b=new BST(a);
	    
	    int beg=sc.nextInt();
	    int end=sc.nextInt();
	    
	    System.out.print("# Preorder : ");
	    b.preOrder();
	    System.out.println();
	    System.out.print("# Nodes within range are : ");
	    b.range(beg,end);
	    System.out.println();
	    t--;
	}
}

}

@tishachhabra2702_8fc5a68a2e295e35 your method of creating the BST is correct but this question demands another method to create BST which is you first have to create a root node = null; and then you have to add each given element one by one in the BST. here add means INSERT into BST one by one. Your insert function should be according to the function given in the below link :

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.