@@ -219,7 +219,7 @@ private void printRootToLeaf(Node rootNode, String previousValue){
219219 public static void main (String [] args ) {
220220
221221 BinarySearchTree binaryTree = new BinarySearchTree ();
222- binaryTree .add (7 );
222+ /* binaryTree.add(7);
223223 binaryTree.add(6);
224224 binaryTree.add(8);
225225 binaryTree.add(3);
@@ -235,7 +235,15 @@ public static void main(String[] args) {
235235 binaryTree.add(15);
236236 binaryTree.add(1);
237237 binaryTree.add(4);
238-
238+ */
239+
240+ binaryTree .add (5 );
241+ binaryTree .add (3 );
242+ binaryTree .add (2 );
243+ binaryTree .add (4 );
244+ binaryTree .add (9 );
245+ binaryTree .add (6 );
246+ binaryTree .add (11 );
239247 System .out .println ("Size of this node is : " +binaryTree .size ());
240248 System .out .println ("Max depth is : " + binaryTree .maxDepth ());
241249 System .out .println ("Min Value is : " + binaryTree .minValue ());
@@ -248,6 +256,27 @@ public static void main(String[] args) {
248256 System .out .print (binaryTree .valueExists (0 ));
249257 System .out .println ();
250258 binaryTree .printRootToLeaf ();
259+
260+ BinarySearchTree bst = new BinarySearchTree ();
261+ createNew (binaryTree .rootNode , 4 ,7 , bst );
262+ System .out .println ("new tree data is : " );
263+ bst .printData ();
251264 }
252265
266+
267+ private static BinarySearchTree createNew (Node root , int min , int max , BinarySearchTree bst ){
268+ if (root !=null ) {
269+ if (root .data >= min && root .data <= max ) {
270+ bst .add (root .data );
271+ }
272+ if (root .data >= min ) {
273+ createNew (root .getLeftNode (), min , max , bst );
274+ }
275+
276+ if (root .data < max ) {
277+ createNew (root .getRightNode (), min , max , bst );
278+ }
279+ }
280+ return bst ;
281+ }
253282}
0 commit comments