Print BST keys in the range

import java.util.*;
public class BST {
private class Node{
int data;
Node left;
Node right;
}
private Node root;

public BST(int[] arr){
	this.root = construct(arr,0,arr.length-1);
}

private Node construct(int[] arr,int lo,int hi){
	if(lo>hi){
		return null;
	}
	int mid=(hi+lo)/2;
	
	Node nn = new Node();
	nn.data = arr[mid];
	nn.left = construct(arr,lo,mid-1);
	nn.right = construct(arr,mid+1,hi);

	return nn;

}

public void inRange(int ll,int ul){
	System.out.print("# Nodes within range are : ");
	 inRange(this.root,ll,ul);
}

private void inRange(Node node,int ll,int ul){
	if(node==null){
		return;
	}
	
		inRange(node.left,ll,ul);
	   inRange(node.right,ll,ul);
	   if(ll<=node.data && node.data<=ul){
			System.out.print(node.data+" ");
		}


}

public void preOrder() {
	System.out.print("# Preorder : ");
	preOrder(this.root);
	System.out.println();
}

private void preOrder(Node node) {
	if(node==null) {
		return;
	}
	
	System.out.print(node.data+" ");
	preOrder(node.left);
	preOrder(node.right);
}

public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
	int T = sc.nextInt();
	while(T>0) {
	int N = sc.nextInt();
	int[] arr = new int[N];
	for(int i=0;i<N;i++) {
		arr[i] = sc.nextInt();
	}
	 Arrays.sort(arr);
	
	int ll = sc.nextInt();
	int ul = sc.nextInt();
	BST tree = new BST(arr);
	tree.preOrder();
	tree.inRange(ll, ul);
	T--;
	}

}}
//sir please check my code I’m getting same answers but in wrong order

@Siddharth_sharma1808,
https://ide.codingblocks.com/s/222586 I have corrected your input format. You don’t have to sort the array. But there still is problem in the inRange method. Follow the algo below and try it out. If you are unable to, kindly reply on this thread. I would be happy to help you.

  1. If value of root’s key is greater than k1, then recursively call in left subtree.
  2. If value of root’s key is in range, then print the root’s key.
  3. If value of root’s key is smaller than k2, then recursively call in right subtree.

sir its giving stack overflow exception

@Siddharth_sharma1808,
https://ide.codingblocks.com/s/222611 Corrected code.