Cannot understand the reason behind the error.
Cannot Understand the error
@2304ambikagupta_35a5bee93bbf353e you have to add another System.out.println(); // after the line l.Print(root,k1,k2);
otherwise for multiple testcases your code will start printing like this :
Preorder : 21 18 2 6 14 24 12 13 3 4
Nodes within range are : 6 # Preorder : 14 17 7 18 12 5 4 6 21 24
Nodes within range are : 12 17 14 # Preorder : 16 11 15 20 2 22 4 25 17 10
Nodes within range are : 17 25 22 20 16 # Preorder : 12 18 9 23 15 13 25 11 22 16
Nodes within range are : 9 11 13 15 12 # Preorder : 15 7 3 17 12 6 8 16 19 2
Nodes within range are : 19 16 12 17 15 # Preorder : 2 3 4 5 6 7 8
Nodes within range are : 4 5 6 7 8
but the correct output format is :
Preorder : 21 18 2 6 14 24 12 13 3 4
Nodes within range are : 6
Preorder : 14 17 7 18 12 5 4 6 21 24
Nodes within range are : 12 17 14
Preorder : 16 11 15 20 2 22 4 25 17 10
Nodes within range are : 17 25 22 20 16
Preorder : 12 18 9 23 15 13 25 11 22 16
Nodes within range are : 9 11 13 15 12
Preorder : 15 7 3 17 12 6 8 16 19 2
Nodes within range are : 19 16 12 17 15
Preorder : 2 3 4 5 6 7 8
Nodes within range are : 4 5 6 7 8
and your Preorder should be according to this :
Form a simple Binary Tree starting with the Root node. Place the next node to the right if it is greater than the root otherwise places it on the left. What I am saying is create a root and insert every node followed in the order given and your insert function should be based on the concept below. Use the concept in the link below :