Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective in JAVA JAVA JAVA JAVA JAVA : Write a program which creates a binary s

ID: 3862808 • Letter: O

Question

Objective in JAVA JAVA JAVA JAVA JAVA:

Write a program which creates a binary search tree of different fruit from a file.

·     The comparison is based on the fruit’s weight

·     The file is tab delimited format goes as follows

o  Fruit Type weight

·     The binary search tree needs to have the following methods

o  insert: inserts a new fruit into the tree

o  delete: deletes the fruit instance. Keep in mind that in order for a fruit to be equal it must have the same same type and weight.

o  print pre-order traversal: Print the data. Next explore the left subtree. Finally right explore subtree.

o  print in-order traversal: Explore the left subtree. Print the data. Finally explore the right subtree.

o  print post-order traversal: Explore the left subtree. Then explore the right subtree. Finally print out the data.

·     Finally write a test file that demonstrates THE POWER OF TREES!!! FRUIT!!! By reading a shape file.

HINTS:

Creating a class for fruit makes this problem so much easier

Having a toString, compareTo, and an equals method would really be useful

Recursion is your friend.

NO BUFFERED READER. Please show output!

File reads as:

Example output:

Welcome to the fruit tree!

Populating tree file file

Printing the in-order traversal

Banana 0.006167454282033358

Orange 0.07967274292009441

Banana 0.09413408636637421

Apple 0.12049892596510792

Apple 0.24516328879201021

Kiwi 0.27100642727895363

Apple 0.30978149002689526

Apple 0.3216606460346705

Tomato 0.3259901339116539

Banana 0.3572110962871161

Kiwi 0.45564459240483524

Apple 0.4859853412170728

Apple 0.603296674503539

Apple 0.6205068678131825

Orange 0.7370861566279563

Banana 0.8249611080979419

Tomato 0.9136235636337187

Kiwi 0.9482193843337194

Tomato 0.9570475745762608

Orange 0.9621352335043648

Tomato 0.9906677529489888

Apple 1.0097048804700366

Kiwi 1.0340475191748726

Banana 1.2295130239577738

Apple 1.2596977062097159

Orange 1.415314546041357

Kiwi 1.5426974863764342

Kiwi 1.5877722583775062

Apple 1.6104335196184982

Banana 1.6365611326426943

Orange 1.6425177539231268

Banana 1.703457163967561

Tomato 1.7502849810509313

Apple 1.9202813393056317

Orange 1.9226762091089729

Orange 1.9579096081143628

Banana 1.9974965504311042

Kiwi 2.011793621529901

Kiwi 2.213939203129497

Tomato 2.287438968525538

Tomato 2.310589336413322

Apple 2.3859195693200412

Banana 2.4012979272659667

Kiwi 2.408573828682015

Banana 2.465349052236099

Orange 2.517329931945071

Orange 2.5568387709811633

Banana 2.5591805544621793

Apple 2.7092949536458164

Apple 2.7179760646130386

Banana 2.7429004129169074

Orange 2.757644307430845

Orange 2.780001649154491

Kiwi 2.7912885879702385

Apple 2.873673933472279

Banana 2.883294535298652

Apple 2.901424898527876

Orange 3.02213500791712

Kiwi 3.130265580641745

Banana 3.1508667661022742

Banana 3.21651584121321

Banana 3.2250175222146633

Banana 3.2401966619579925

Apple 3.3261168784899335

Apple 3.4067654081096292

Kiwi 3.4113369395371054

Kiwi 3.421597330474709

Banana 3.4720359583562126

Tomato 3.497931384921258

Apple 3.514259115351504

Orange 3.545459485746505

Banana 3.615339037449382

Banana 3.6494527648643906

Kiwi 3.6566367557127104

Tomato 3.6568222763434206

Banana 3.714749888189644

Tomato 3.826549862259843

Tomato 3.91505462517807

Kiwi 3.9629238331885324

Kiwi 3.9930885812782018

Orange 4.153591707921256

Tomato 4.272392839694168

Orange 4.36635444379318

Apple 4.391919428583659

Apple 4.393777226918403

Banana 4.433034496372054

Tomato 4.526667348325462

Banana 4.53176969188548

Kiwi 4.540499450437838

Tomato 4.546460476028497

Orange 4.625294775272419

Apple 4.658519644572135

Apple 4.689654965283379

Apple 4.743952143832523

Tomato 4.847156403059746

Banana 4.849541488248527

Kiwi 4.859249812594946

Tomato 4.915155758224849

Banana 4.966555043577987

Kiwi 4.969338821021524

Printing the pre-order traversal

Apple 0.4859853412170728

Apple 0.30978149002689526

Orange 0.07967274292009441

Banana 0.006167454282033358

Banana 0.09413408636637421

Apple 0.12049892596510792

Apple 0.24516328879201021

Kiwi 0.27100642727895363

Kiwi 0.45564459240483524

Apple 0.3216606460346705

Tomato 0.3259901339116539

Banana 0.3572110962871161

Apple 4.658519644572135

Orange 2.757644307430845

Tomato 0.9570475745762608

Tomato 0.9136235636337187

Banana 0.8249611080979419

Apple 0.6205068678131825

Apple 0.603296674503539

Orange 0.7370861566279563

Kiwi 0.9482193843337194

Banana 1.6365611326426943

Kiwi 1.0340475191748726

Apple 1.0097048804700366

Tomato 0.9906677529489888

Orange 0.9621352335043648

Kiwi 1.5877722583775062

Banana 1.2295130239577738

Apple 1.2596977062097159

Kiwi 1.5426974863764342

Orange 1.415314546041357

Apple 1.6104335196184982

Banana 1.703457163967561

Orange 1.6425177539231268

Tomato 2.287438968525538

Kiwi 2.213939203129497

Kiwi 2.011793621529901

Apple 1.9202813393056317

Tomato 1.7502849810509313

Orange 1.9579096081143628

Orange 1.9226762091089729

Banana 1.9974965504311042

Kiwi 2.408573828682015

Tomato 2.310589336413322

Banana 2.4012979272659667

Apple 2.3859195693200412

Orange 2.517329931945071

Banana 2.465349052236099

Apple 2.7092949536458164

Banana 2.5591805544621793

Orange 2.5568387709811633

Apple 2.7179760646130386

Banana 2.7429004129169074

Orange 4.36635444379318

Tomato 4.272392839694168

Tomato 3.91505462517807

Banana 3.2250175222146633

Kiwi 2.7912885879702385

Orange 2.780001649154491

Banana 3.1508667661022742

Apple 2.901424898527876

Apple 2.873673933472279

Banana 2.883294535298652

Orange 3.02213500791712

Kiwi 3.130265580641745

Banana 3.21651584121321

Apple 3.514259115351504

Tomato 3.497931384921258

Kiwi 3.4113369395371054

Apple 3.3261168784899335

Banana 3.2401966619579925

Apple 3.4067654081096292

Banana 3.4720359583562126

Kiwi 3.421597330474709

Orange 3.545459485746505

Banana 3.714749888189644

Kiwi 3.6566367557127104

Banana 3.6494527648643906

Banana 3.615339037449382

Tomato 3.6568222763434206

Tomato 3.826549862259843

Orange 4.153591707921256

Kiwi 3.9629238331885324

Kiwi 3.9930885812782018

Tomato 4.526667348325462

Apple 4.393777226918403

Apple 4.391919428583659

Banana 4.433034496372054

Tomato 4.546460476028497

Banana 4.53176969188548

Kiwi 4.540499450437838

Orange 4.625294775272419

Tomato 4.847156403059746

Apple 4.689654965283379

Apple 4.743952143832523

Banana 4.849541488248527

Tomato 4.915155758224849

Kiwi 4.859249812594946

Banana 4.966555043577987

Kiwi 4.969338821021524

Printing the post-order traversal

Banana 0.006167454282033358

Kiwi 0.27100642727895363

Apple 0.24516328879201021

Apple 0.12049892596510792

Banana 0.09413408636637421

Orange 0.07967274292009441

Banana 0.3572110962871161

Tomato 0.3259901339116539

Apple 0.3216606460346705

Kiwi 0.45564459240483524

Apple 0.30978149002689526

Apple 0.603296674503539

Orange 0.7370861566279563

Apple 0.6205068678131825

Banana 0.8249611080979419

Kiwi 0.9482193843337194

Tomato 0.9136235636337187

Orange 0.9621352335043648

Tomato 0.9906677529489888

Apple 1.0097048804700366

Orange 1.415314546041357

Kiwi 1.5426974863764342

Apple 1.2596977062097159

Banana 1.2295130239577738

Apple 1.6104335196184982

Kiwi 1.5877722583775062

Kiwi 1.0340475191748726

Orange 1.6425177539231268

Tomato 1.7502849810509313

Orange 1.9226762091089729

Banana 1.9974965504311042

Orange 1.9579096081143628

Apple 1.9202813393056317

Kiwi 2.011793621529901

Kiwi 2.213939203129497

Apple 2.3859195693200412

Banana 2.4012979272659667

Tomato 2.310589336413322

Banana 2.465349052236099

Orange 2.5568387709811633

Banana 2.5591805544621793

Banana 2.7429004129169074

Apple 2.7179760646130386

Apple 2.7092949536458164

Orange 2.517329931945071

Kiwi 2.408573828682015

Tomato 2.287438968525538

Banana 1.703457163967561

Banana 1.6365611326426943

Tomato 0.9570475745762608

Orange 2.780001649154491

Banana 2.883294535298652

Apple 2.873673933472279

Kiwi 3.130265580641745

Orange 3.02213500791712

Apple 2.901424898527876

Banana 3.21651584121321

Banana 3.1508667661022742

Kiwi 2.7912885879702385

Banana 3.2401966619579925

Apple 3.4067654081096292

Apple 3.3261168784899335

Kiwi 3.421597330474709

Banana 3.4720359583562126

Kiwi 3.4113369395371054

Tomato 3.497931384921258

Banana 3.615339037449382

Banana 3.6494527648643906

Tomato 3.6568222763434206

Kiwi 3.6566367557127104

Tomato 3.826549862259843

Banana 3.714749888189644

Orange 3.545459485746505

Apple 3.514259115351504

Banana 3.2250175222146633

Kiwi 3.9930885812782018

Kiwi 3.9629238331885324

Orange 4.153591707921256

Tomato 3.91505462517807

Tomato 4.272392839694168

Apple 4.391919428583659

Banana 4.433034496372054

Apple 4.393777226918403

Kiwi 4.540499450437838

Banana 4.53176969188548

Orange 4.625294775272419

Tomato 4.546460476028497

Tomato 4.526667348325462

Orange 4.36635444379318

Orange 2.757644307430845

Apple 4.743952143832523

Apple 4.689654965283379

Kiwi 4.859249812594946

Kiwi 4.969338821021524

Banana 4.966555043577987

Tomato 4.915155758224849

Banana 4.849541488248527

Tomato 4.847156403059746

Apple 4.658519644572135

Apple 0.4859853412170728

Deleting Apple 0.4859853412170728

Printing in-order traversal

Banana 0.006167454282033358

Orange 0.07967274292009441

Banana 0.09413408636637421

Apple 0.12049892596510792

Apple 0.24516328879201021

Kiwi 0.27100642727895363

Apple 0.30978149002689526

Apple 0.3216606460346705

Tomato 0.3259901339116539

Banana 0.3572110962871161

Kiwi 0.45564459240483524

Apple 0.603296674503539

Apple 0.6205068678131825

Orange 0.7370861566279563

Banana 0.8249611080979419

Tomato 0.9136235636337187

Kiwi 0.9482193843337194

Tomato 0.9570475745762608

Orange 0.9621352335043648

Tomato 0.9906677529489888

Apple 1.0097048804700366

Kiwi 1.0340475191748726

Banana 1.2295130239577738

Apple 1.2596977062097159

Orange 1.415314546041357

Kiwi 1.5426974863764342

Kiwi 1.5877722583775062

Apple 1.6104335196184982

Banana 1.6365611326426943

Orange 1.6425177539231268

Banana 1.703457163967561

Tomato 1.7502849810509313

Apple 1.9202813393056317

Orange 1.9226762091089729

Orange 1.9579096081143628

Banana 1.9974965504311042

Kiwi 2.011793621529901

Kiwi 2.213939203129497

Tomato 2.287438968525538

Tomato 2.310589336413322

Apple 2.3859195693200412

Banana 2.4012979272659667

Kiwi 2.408573828682015

Banana 2.465349052236099

Orange 2.517329931945071

Orange 2.5568387709811633

Banana 2.5591805544621793

Apple 2.7092949536458164

Apple 2.7179760646130386

Banana 2.7429004129169074

Orange 2.757644307430845

Orange 2.780001649154491

Kiwi 2.7912885879702385

Apple 2.873673933472279

Banana 2.883294535298652

Apple 2.901424898527876

Orange 3.02213500791712

Kiwi 3.130265580641745

Banana 3.1508667661022742

Banana 3.21651584121321

Banana 3.2250175222146633

Banana 3.2401966619579925

Apple 3.3261168784899335

Apple 3.4067654081096292

Kiwi 3.4113369395371054

Kiwi 3.421597330474709

Banana 3.4720359583562126

Tomato 3.497931384921258

Apple 3.514259115351504

Orange 3.545459485746505

Banana 3.615339037449382

Banana 3.6494527648643906

Kiwi 3.6566367557127104

Tomato 3.6568222763434206

Banana 3.714749888189644

Tomato 3.826549862259843

Tomato 3.91505462517807

Kiwi 3.9629238331885324

Kiwi 3.9930885812782018

Orange 4.153591707921256

Tomato 4.272392839694168

Orange 4.36635444379318

Apple 4.391919428583659

Apple 4.393777226918403

Banana 4.433034496372054

Tomato 4.526667348325462

Banana 4.53176969188548

Kiwi 4.540499450437838

Tomato 4.546460476028497

Orange 4.625294775272419

Apple 4.658519644572135

Apple 4.689654965283379

Apple 4.743952143832523

Tomato 4.847156403059746

Banana 4.849541488248527

Kiwi 4.859249812594946

Tomato 4.915155758224849

Banana 4.966555043577987

Kiwi 4.969338821021524

Explanation / Answer

Fruit.java


public class Fruit implements Comparable<Fruit>{
   String fruitType;
   double weight;
   public Fruit(String fruitType, double weight) {
       this.fruitType = fruitType;
       this.weight = weight;
   }
  
   public String toString() {
       return "Type: " + fruitType + ", Weight: " + weight;
   }

   @Override
   public int compareTo(Fruit f) {
       if(f.weight > weight) {
           return 1;
       } else {
           return 0;
       }
   }
}



BinaryTree.java:


import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class BinaryTree {

   public static void main(String[] args) throws IOException {
       new BinaryTree().run();
   }

   static class Node {
       Node left;
       Node right;
       Fruit fruit;

       public Node(Fruit fruit) {
           this.fruit = fruit;
       }
   }

   //Driver function
   public void run() throws IOException {
       System.out.println("Welcome to the fruit tree!");
      
       Scanner reader = new Scanner(new FileReader("input.txt"));
       System.out.println("Populating tree file file");
      
       String line;
       Node rootNode = null;
      
       // while there are entries
       while(reader.hasNextLine()){
           line = reader.nextLine();
           // split by comma
           String tokens[] = line.split(" ");
           if(tokens.length == 2) {
               if(rootNode == null) {
                   // create root node
                   rootNode = new Node(new Fruit(tokens[0], Double.parseDouble(tokens[1])));
               } else {
                   // insert element to tree rooted with root node
                   insert(rootNode, tokens[0], Double.parseDouble(tokens[1]));
               }
           }
       }      
      
       // close the reader
       reader.close();

       System.out.println(" Printing the in-order traversal");
       printInOrder(rootNode);
       System.out.println(" Printing the pre-order traversal");
       printPreOrder(rootNode);
       System.out.println(" Printing the post-order traversal");
       printPostOrder(rootNode);
   }


public static Node minimumElement(Node root) {
       if (root.left == null)
           return root;
       else {
           return minimumElement(root.left);
       }
   }

   public static Node deleteNode(Node root, Fruit f) {
       if (root == null)
           return null;
       if (root.fruit.compareTo(f) > 0) {
           root.left = deleteNode(root.left, f);
       } else if (root.fruit.compareTo(f) < 0) {
           root.right = deleteNode(root.right, f);

       } else {
           // if nodeToBeDeleted have both children
           if (root.left != null && root.right != null) {
               Node temp = root;
               // Finding minimum element from right
               Node minNodeForRight = minimumElement(temp.right);
               // Replacing current node with minimum node from right subtree
               root.fruit = minNodeForRight.fruit;
               // Deleting minimum node from right now
               deleteNode(root.right, minNodeForRight.fruit);

           }
           // if nodeToBeDeleted has only left child
           else if (root.left != null) {
               root = root.left;
           }
           // if nodeToBeDeleted has only right child
           else if (root.right != null) {
               root = root.right;
           }
           // if nodeToBeDeleted do not have child (Leaf node)
           else
               root = null;
       }
       return root;
   }

   /*
   * To inset a node in the tree
   */
   public void insert(Node node, String fruitType, double weight) {
       if (weight < node.fruit.weight) {
           if (node.left != null) {
               insert(node.left, fruitType, weight);
           } else {
               System.out.println(" Inserted " + fruitType + ", " + weight + " to left of node "
                       + node.fruit);
               node.left = new Node(new Fruit(fruitType, weight));
           }
       } else if (weight > node.fruit.weight) {
           if (node.right != null) {
               insert(node.right, fruitType, weight);
           } else {
               System.out.println(" Inserted " + fruitType + ", " + weight + " to right of node "
                       + node.fruit);
               node.right = new Node(new Fruit(fruitType, weight));
           }
       }
   }

   /*
   * Print all the nodes in pre order fashion
   */
   public void printPreOrder(Node node) {
       if (node != null) {
           System.out.println(" Traversed: " + node.fruit);
           printInOrder(node.left);
           printInOrder(node.right);
       }
   }

   /*
   * Print all the nodes in inorder fashion
   */
   public void printInOrder(Node node) {
       if (node != null) {
           printInOrder(node.left);
           System.out.println(" Traversed: " + node.fruit);
           printInOrder(node.right);
       }
   }
  
   /*
   * Print all the nodes in postorder fashion
   */
   public void printPostOrder(Node node) {
       if (node != null) {
           printPostOrder(node.right);
           System.out.println(" Traversed: " + node.fruit);
           printPostOrder(node.left);
       }
   }
}



BinaryTree.java has got the main method, which reads the input file(input.txt) from same directory and gives the output:

Sample Output:

Welcome to the fruit tree!
Populating tree file file
Inserted Apple, 4.658519644572135 to right of node Type: Apple, Weight: 0.4859853412170728
Inserted Orange, 2.757644307430845 to left of node Type: Apple, Weight: 4.658519644572135
Inserted Orange, 4.36635444379318 to right of node Type: Orange, Weight: 2.757644307430845
Inserted Tomato, 0.9570475745762608 to left of node Type: Orange, Weight: 2.757644307430845
Inserted Banana, 1.6365611326426943 to right of node Type: Tomato, Weight: 0.9570475745762608
Inserted Tomato, 0.9136235636337187 to left of node Type: Tomato, Weight: 0.9570475745762608
Inserted Banana, 1.703457163967561 to right of node Type: Banana, Weight: 1.6365611326426943
Inserted Tomato, 4.272392839694168 to left of node Type: Orange, Weight: 4.36635444379318
Inserted Tomato, 2.287438968525538 to right of node Type: Banana, Weight: 1.703457163967561
Inserted Kiwi, 1.0340475191748726 to left of node Type: Banana, Weight: 1.6365611326426943
Inserted Kiwi, 2.408573828682015 to right of node Type: Tomato, Weight: 2.287438968525538
Inserted Tomato, 3.91505462517807 to left of node Type: Tomato, Weight: 4.272392839694168
Inserted Orange, 4.153591707921256 to right of node Type: Tomato, Weight: 3.91505462517807
Inserted Banana, 3.2250175222146633 to left of node Type: Tomato, Weight: 3.91505462517807
Inserted Kiwi, 2.213939203129497 to left of node Type: Tomato, Weight: 2.287438968525538
Inserted Apple, 1.0097048804700366 to left of node Type: Kiwi, Weight: 1.0340475191748726
Inserted Tomato, 4.526667348325462 to right of node Type: Orange, Weight: 4.36635444379318
Inserted Apple, 0.30978149002689526 to left of node Type: Apple, Weight: 0.4859853412170728
Inserted Apple, 4.393777226918403 to left of node Type: Tomato, Weight: 4.526667348325462
Inserted Orange, 2.517329931945071 to right of node Type: Kiwi, Weight: 2.408573828682015
Inserted Kiwi, 3.9629238331885324 to left of node Type: Orange, Weight: 4.153591707921256
Inserted Tomato, 4.546460476028497 to right of node Type: Tomato, Weight: 4.526667348325462
Inserted Apple, 3.514259115351504 to right of node Type: Banana, Weight: 3.2250175222146633
Inserted Tomato, 4.847156403059746 to right of node Type: Apple, Weight: 4.658519644572135
Inserted Kiwi, 1.5877722583775062 to right of node Type: Kiwi, Weight: 1.0340475191748726
Inserted Tomato, 3.497931384921258 to left of node Type: Apple, Weight: 3.514259115351504
Inserted Kiwi, 2.011793621529901 to left of node Type: Kiwi, Weight: 2.213939203129497
Inserted Kiwi, 0.45564459240483524 to right of node Type: Apple, Weight: 0.30978149002689526
Inserted Kiwi, 0.9482193843337194 to right of node Type: Tomato, Weight: 0.9136235636337187
Inserted Apple, 4.689654965283379 to left of node Type: Tomato, Weight: 4.847156403059746
Inserted Banana, 0.8249611080979419 to left of node Type: Tomato, Weight: 0.9136235636337187
Inserted Apple, 1.6104335196184982 to right of node Type: Kiwi, Weight: 1.5877722583775062
Inserted Orange, 0.07967274292009441 to left of node Type: Apple, Weight: 0.30978149002689526
Inserted Kiwi, 3.4113369395371054 to left of node Type: Tomato, Weight: 3.497931384921258
Inserted Apple, 2.7092949536458164 to right of node Type: Orange, Weight: 2.517329931945071
Inserted Apple, 0.6205068678131825 to left of node Type: Banana, Weight: 0.8249611080979419
Inserted Apple, 0.3216606460346705 to left of node Type: Kiwi, Weight: 0.45564459240483524
Inserted Banana, 0.006167454282033358 to left of node Type: Orange, Weight: 0.07967274292009441
Inserted Apple, 1.9202813393056317 to left of node Type: Kiwi, Weight: 2.011793621529901
Inserted Orange, 1.9579096081143628 to right of node Type: Apple, Weight: 1.9202813393056317
Inserted Banana, 0.09413408636637421 to right of node Type: Orange, Weight: 0.07967274292009441
Inserted Banana, 4.849541488248527 to right of node Type: Tomato, Weight: 4.847156403059746
Inserted Apple, 2.7179760646130386 to right of node Type: Apple, Weight: 2.7092949536458164
Inserted Apple, 0.603296674503539 to left of node Type: Apple, Weight: 0.6205068678131825
Inserted Tomato, 4.915155758224849 to right of node Type: Banana, Weight: 4.849541488248527
Inserted Banana, 3.4720359583562126 to right of node Type: Kiwi, Weight: 3.4113369395371054
Inserted Orange, 3.545459485746505 to right of node Type: Apple, Weight: 3.514259115351504
Inserted Banana, 4.966555043577987 to right of node Type: Tomato, Weight: 4.915155758224849
Inserted Kiwi, 4.969338821021524 to right of node Type: Banana, Weight: 4.966555043577987
Inserted Orange, 4.625294775272419 to right of node Type: Tomato, Weight: 4.546460476028497
Inserted Kiwi, 2.7912885879702385 to left of node Type: Banana, Weight: 3.2250175222146633
Inserted Tomato, 0.9906677529489888 to left of node Type: Apple, Weight: 1.0097048804700366
Inserted Apple, 3.3261168784899335 to left of node Type: Kiwi, Weight: 3.4113369395371054
Inserted Orange, 1.6425177539231268 to left of node Type: Banana, Weight: 1.703457163967561
Inserted Banana, 3.1508667661022742 to right of node Type: Kiwi, Weight: 2.7912885879702385
Inserted Banana, 3.714749888189644 to right of node Type: Orange, Weight: 3.545459485746505
Inserted Apple, 4.743952143832523 to right of node Type: Apple, Weight: 4.689654965283379
Inserted Banana, 1.9974965504311042 to right of node Type: Orange, Weight: 1.9579096081143628
Inserted Tomato, 1.7502849810509313 to left of node Type: Apple, Weight: 1.9202813393056317
Inserted Apple, 0.12049892596510792 to right of node Type: Banana, Weight: 0.09413408636637421
Inserted Apple, 2.901424898527876 to left of node Type: Banana, Weight: 3.1508667661022742
Inserted Banana, 1.2295130239577738 to left of node Type: Kiwi, Weight: 1.5877722583775062
Inserted Apple, 0.24516328879201021 to right of node Type: Apple, Weight: 0.12049892596510792
Inserted Banana, 4.53176969188548 to left of node Type: Tomato, Weight: 4.546460476028497
Inserted Apple, 2.873673933472279 to left of node Type: Apple, Weight: 2.901424898527876
Inserted Apple, 1.2596977062097159 to right of node Type: Banana, Weight: 1.2295130239577738
Inserted Orange, 3.02213500791712 to right of node Type: Apple, Weight: 2.901424898527876
Inserted Kiwi, 3.9930885812782018 to right of node Type: Kiwi, Weight: 3.9629238331885324
Inserted Orange, 0.9621352335043648 to left of node Type: Tomato, Weight: 0.9906677529489888
Inserted Banana, 2.883294535298652 to right of node Type: Apple, Weight: 2.873673933472279
Inserted Orange, 0.7370861566279563 to right of node Type: Apple, Weight: 0.6205068678131825
Inserted Orange, 2.780001649154491 to left of node Type: Kiwi, Weight: 2.7912885879702385
Inserted Tomato, 2.310589336413322 to left of node Type: Kiwi, Weight: 2.408573828682015
Inserted Kiwi, 4.859249812594946 to left of node Type: Tomato, Weight: 4.915155758224849
Inserted Kiwi, 3.6566367557127104 to left of node Type: Banana, Weight: 3.714749888189644
Inserted Banana, 3.6494527648643906 to left of node Type: Kiwi, Weight: 3.6566367557127104
Inserted Banana, 2.5591805544621793 to left of node Type: Apple, Weight: 2.7092949536458164
Inserted Banana, 4.433034496372054 to right of node Type: Apple, Weight: 4.393777226918403
Inserted Kiwi, 3.421597330474709 to left of node Type: Banana, Weight: 3.4720359583562126
Inserted Tomato, 0.3259901339116539 to right of node Type: Apple, Weight: 0.3216606460346705
Inserted Kiwi, 1.5426974863764342 to right of node Type: Apple, Weight: 1.2596977062097159
Inserted Apple, 4.391919428583659 to left of node Type: Apple, Weight: 4.393777226918403
Inserted Tomato, 3.826549862259843 to right of node Type: Banana, Weight: 3.714749888189644
Inserted Kiwi, 4.540499450437838 to right of node Type: Banana, Weight: 4.53176969188548
Inserted Apple, 3.4067654081096292 to right of node Type: Apple, Weight: 3.3261168784899335
Inserted Banana, 0.3572110962871161 to right of node Type: Tomato, Weight: 0.3259901339116539
Inserted Kiwi, 0.27100642727895363 to right of node Type: Apple, Weight: 0.24516328879201021
Inserted Banana, 3.2401966619579925 to left of node Type: Apple, Weight: 3.3261168784899335
Inserted Tomato, 3.6568222763434206 to right of node Type: Kiwi, Weight: 3.6566367557127104
Inserted Kiwi, 3.130265580641745 to right of node Type: Orange, Weight: 3.02213500791712
Inserted Orange, 2.5568387709811633 to left of node Type: Banana, Weight: 2.5591805544621793
Inserted Banana, 3.21651584121321 to right of node Type: Banana, Weight: 3.1508667661022742
Inserted Banana, 2.465349052236099 to left of node Type: Orange, Weight: 2.517329931945071
Inserted Banana, 3.615339037449382 to left of node Type: Banana, Weight: 3.6494527648643906
Inserted Orange, 1.415314546041357 to left of node Type: Kiwi, Weight: 1.5426974863764342
Inserted Banana, 2.7429004129169074 to right of node Type: Apple, Weight: 2.7179760646130386
Inserted Orange, 1.9226762091089729 to left of node Type: Orange, Weight: 1.9579096081143628
Inserted Banana, 2.4012979272659667 to right of node Type: Tomato, Weight: 2.310589336413322
Inserted Apple, 2.3859195693200412 to left of node Type: Banana, Weight: 2.4012979272659667


Printing the in-order traversal
Traversed: Type: Banana, Weight: 0.006167454282033358
Traversed: Type: Orange, Weight: 0.07967274292009441
Traversed: Type: Banana, Weight: 0.09413408636637421
Traversed: Type: Apple, Weight: 0.12049892596510792
Traversed: Type: Apple, Weight: 0.24516328879201021
Traversed: Type: Kiwi, Weight: 0.27100642727895363
Traversed: Type: Apple, Weight: 0.30978149002689526
Traversed: Type: Apple, Weight: 0.3216606460346705
Traversed: Type: Tomato, Weight: 0.3259901339116539
Traversed: Type: Banana, Weight: 0.3572110962871161
Traversed: Type: Kiwi, Weight: 0.45564459240483524
Traversed: Type: Apple, Weight: 0.4859853412170728
Traversed: Type: Apple, Weight: 0.603296674503539
Traversed: Type: Apple, Weight: 0.6205068678131825
Traversed: Type: Orange, Weight: 0.7370861566279563
Traversed: Type: Banana, Weight: 0.8249611080979419
Traversed: Type: Tomato, Weight: 0.9136235636337187
Traversed: Type: Kiwi, Weight: 0.9482193843337194
Traversed: Type: Tomato, Weight: 0.9570475745762608
Traversed: Type: Orange, Weight: 0.9621352335043648
Traversed: Type: Tomato, Weight: 0.9906677529489888
Traversed: Type: Apple, Weight: 1.0097048804700366
Traversed: Type: Kiwi, Weight: 1.0340475191748726
Traversed: Type: Banana, Weight: 1.2295130239577738
Traversed: Type: Apple, Weight: 1.2596977062097159
Traversed: Type: Orange, Weight: 1.415314546041357
Traversed: Type: Kiwi, Weight: 1.5426974863764342
Traversed: Type: Kiwi, Weight: 1.5877722583775062
Traversed: Type: Apple, Weight: 1.6104335196184982
Traversed: Type: Banana, Weight: 1.6365611326426943
Traversed: Type: Orange, Weight: 1.6425177539231268
Traversed: Type: Banana, Weight: 1.703457163967561
Traversed: Type: Tomato, Weight: 1.7502849810509313
Traversed: Type: Apple, Weight: 1.9202813393056317
Traversed: Type: Orange, Weight: 1.9226762091089729
Traversed: Type: Orange, Weight: 1.9579096081143628
Traversed: Type: Banana, Weight: 1.9974965504311042
Traversed: Type: Kiwi, Weight: 2.011793621529901
Traversed: Type: Kiwi, Weight: 2.213939203129497
Traversed: Type: Tomato, Weight: 2.287438968525538
Traversed: Type: Tomato, Weight: 2.310589336413322
Traversed: Type: Apple, Weight: 2.3859195693200412
Traversed: Type: Banana, Weight: 2.4012979272659667
Traversed: Type: Kiwi, Weight: 2.408573828682015
Traversed: Type: Banana, Weight: 2.465349052236099
Traversed: Type: Orange, Weight: 2.517329931945071
Traversed: Type: Orange, Weight: 2.5568387709811633
Traversed: Type: Banana, Weight: 2.5591805544621793
Traversed: Type: Apple, Weight: 2.7092949536458164
Traversed: Type: Apple, Weight: 2.7179760646130386
Traversed: Type: Banana, Weight: 2.7429004129169074
Traversed: Type: Orange, Weight: 2.757644307430845
Traversed: Type: Orange, Weight: 2.780001649154491
Traversed: Type: Kiwi, Weight: 2.7912885879702385
Traversed: Type: Apple, Weight: 2.873673933472279
Traversed: Type: Banana, Weight: 2.883294535298652
Traversed: Type: Apple, Weight: 2.901424898527876
Traversed: Type: Orange, Weight: 3.02213500791712
Traversed: Type: Kiwi, Weight: 3.130265580641745
Traversed: Type: Banana, Weight: 3.1508667661022742
Traversed: Type: Banana, Weight: 3.21651584121321
Traversed: Type: Banana, Weight: 3.2250175222146633
Traversed: Type: Banana, Weight: 3.2401966619579925
Traversed: Type: Apple, Weight: 3.3261168784899335
Traversed: Type: Apple, Weight: 3.4067654081096292
Traversed: Type: Kiwi, Weight: 3.4113369395371054
Traversed: Type: Kiwi, Weight: 3.421597330474709
Traversed: Type: Banana, Weight: 3.4720359583562126
Traversed: Type: Tomato, Weight: 3.497931384921258
Traversed: Type: Apple, Weight: 3.514259115351504
Traversed: Type: Orange, Weight: 3.545459485746505
Traversed: Type: Banana, Weight: 3.615339037449382
Traversed: Type: Banana, Weight: 3.6494527648643906
Traversed: Type: Kiwi, Weight: 3.6566367557127104
Traversed: Type: Tomato, Weight: 3.6568222763434206
Traversed: Type: Banana, Weight: 3.714749888189644
Traversed: Type: Tomato, Weight: 3.826549862259843
Traversed: Type: Tomato, Weight: 3.91505462517807
Traversed: Type: Kiwi, Weight: 3.9629238331885324
Traversed: Type: Kiwi, Weight: 3.9930885812782018
Traversed: Type: Orange, Weight: 4.153591707921256
Traversed: Type: Tomato, Weight: 4.272392839694168
Traversed: Type: Orange, Weight: 4.36635444379318
Traversed: Type: Apple, Weight: 4.391919428583659
Traversed: Type: Apple, Weight: 4.393777226918403
Traversed: Type: Banana, Weight: 4.433034496372054
Traversed: Type: Tomato, Weight: 4.526667348325462
Traversed: Type: Banana, Weight: 4.53176969188548
Traversed: Type: Kiwi, Weight: 4.540499450437838
Traversed: Type: Tomato, Weight: 4.546460476028497
Traversed: Type: Orange, Weight: 4.625294775272419
Traversed: Type: Apple, Weight: 4.658519644572135
Traversed: Type: Apple, Weight: 4.689654965283379
Traversed: Type: Apple, Weight: 4.743952143832523
Traversed: Type: Tomato, Weight: 4.847156403059746
Traversed: Type: Banana, Weight: 4.849541488248527
Traversed: Type: Kiwi, Weight: 4.859249812594946
Traversed: Type: Tomato, Weight: 4.915155758224849
Traversed: Type: Banana, Weight: 4.966555043577987
Traversed: Type: Kiwi, Weight: 4.969338821021524


Printing the pre-order traversal
Traversed: Type: Apple, Weight: 0.4859853412170728
Traversed: Type: Banana, Weight: 0.006167454282033358
Traversed: Type: Orange, Weight: 0.07967274292009441
Traversed: Type: Banana, Weight: 0.09413408636637421
Traversed: Type: Apple, Weight: 0.12049892596510792
Traversed: Type: Apple, Weight: 0.24516328879201021
Traversed: Type: Kiwi, Weight: 0.27100642727895363
Traversed: Type: Apple, Weight: 0.30978149002689526
Traversed: Type: Apple, Weight: 0.3216606460346705
Traversed: Type: Tomato, Weight: 0.3259901339116539
Traversed: Type: Banana, Weight: 0.3572110962871161
Traversed: Type: Kiwi, Weight: 0.45564459240483524
Traversed: Type: Apple, Weight: 0.603296674503539
Traversed: Type: Apple, Weight: 0.6205068678131825
Traversed: Type: Orange, Weight: 0.7370861566279563
Traversed: Type: Banana, Weight: 0.8249611080979419
Traversed: Type: Tomato, Weight: 0.9136235636337187
Traversed: Type: Kiwi, Weight: 0.9482193843337194
Traversed: Type: Tomato, Weight: 0.9570475745762608
Traversed: Type: Orange, Weight: 0.9621352335043648
Traversed: Type: Tomato, Weight: 0.9906677529489888
Traversed: Type: Apple, Weight: 1.0097048804700366
Traversed: Type: Kiwi, Weight: 1.0340475191748726
Traversed: Type: Banana, Weight: 1.2295130239577738
Traversed: Type: Apple, Weight: 1.2596977062097159
Traversed: Type: Orange, Weight: 1.415314546041357
Traversed: Type: Kiwi, Weight: 1.5426974863764342
Traversed: Type: Kiwi, Weight: 1.5877722583775062
Traversed: Type: Apple, Weight: 1.6104335196184982
Traversed: Type: Banana, Weight: 1.6365611326426943
Traversed: Type: Orange, Weight: 1.6425177539231268
Traversed: Type: Banana, Weight: 1.703457163967561
Traversed: Type: Tomato, Weight: 1.7502849810509313
Traversed: Type: Apple, Weight: 1.9202813393056317
Traversed: Type: Orange, Weight: 1.9226762091089729
Traversed: Type: Orange, Weight: 1.9579096081143628
Traversed: Type: Banana, Weight: 1.9974965504311042
Traversed: Type: Kiwi, Weight: 2.011793621529901
Traversed: Type: Kiwi, Weight: 2.213939203129497
Traversed: Type: Tomato, Weight: 2.287438968525538
Traversed: Type: Tomato, Weight: 2.310589336413322
Traversed: Type: Apple, Weight: 2.3859195693200412
Traversed: Type: Banana, Weight: 2.4012979272659667
Traversed: Type: Kiwi, Weight: 2.408573828682015
Traversed: Type: Banana, Weight: 2.465349052236099
Traversed: Type: Orange, Weight: 2.517329931945071
Traversed: Type: Orange, Weight: 2.5568387709811633
Traversed: Type: Banana, Weight: 2.5591805544621793
Traversed: Type: Apple, Weight: 2.7092949536458164
Traversed: Type: Apple, Weight: 2.7179760646130386
Traversed: Type: Banana, Weight: 2.7429004129169074
Traversed: Type: Orange, Weight: 2.757644307430845
Traversed: Type: Orange, Weight: 2.780001649154491
Traversed: Type: Kiwi, Weight: 2.7912885879702385
Traversed: Type: Apple, Weight: 2.873673933472279
Traversed: Type: Banana, Weight: 2.883294535298652
Traversed: Type: Apple, Weight: 2.901424898527876
Traversed: Type: Orange, Weight: 3.02213500791712
Traversed: Type: Kiwi, Weight: 3.130265580641745
Traversed: Type: Banana, Weight: 3.1508667661022742
Traversed: Type: Banana, Weight: 3.21651584121321
Traversed: Type: Banana, Weight: 3.2250175222146633
Traversed: Type: Banana, Weight: 3.2401966619579925
Traversed: Type: Apple, Weight: 3.3261168784899335
Traversed: Type: Apple, Weight: 3.4067654081096292
Traversed: Type: Kiwi, Weight: 3.4113369395371054
Traversed: Type: Kiwi, Weight: 3.421597330474709
Traversed: Type: Banana, Weight: 3.4720359583562126
Traversed: Type: Tomato, Weight: 3.497931384921258
Traversed: Type: Apple, Weight: 3.514259115351504
Traversed: Type: Orange, Weight: 3.545459485746505
Traversed: Type: Banana, Weight: 3.615339037449382
Traversed: Type: Banana, Weight: 3.6494527648643906
Traversed: Type: Kiwi, Weight: 3.6566367557127104
Traversed: Type: Tomato, Weight: 3.6568222763434206
Traversed: Type: Banana, Weight: 3.714749888189644
Traversed: Type: Tomato, Weight: 3.826549862259843
Traversed: Type: Tomato, Weight: 3.91505462517807
Traversed: Type: Kiwi, Weight: 3.9629238331885324
Traversed: Type: Kiwi, Weight: 3.9930885812782018
Traversed: Type: Orange, Weight: 4.153591707921256
Traversed: Type: Tomato, Weight: 4.272392839694168
Traversed: Type: Orange, Weight: 4.36635444379318
Traversed: Type: Apple, Weight: 4.391919428583659
Traversed: Type: Apple, Weight: 4.393777226918403
Traversed: Type: Banana, Weight: 4.433034496372054
Traversed: Type: Tomato, Weight: 4.526667348325462
Traversed: Type: Banana, Weight: 4.53176969188548
Traversed: Type: Kiwi, Weight: 4.540499450437838
Traversed: Type: Tomato, Weight: 4.546460476028497
Traversed: Type: Orange, Weight: 4.625294775272419
Traversed: Type: Apple, Weight: 4.658519644572135
Traversed: Type: Apple, Weight: 4.689654965283379
Traversed: Type: Apple, Weight: 4.743952143832523
Traversed: Type: Tomato, Weight: 4.847156403059746
Traversed: Type: Banana, Weight: 4.849541488248527
Traversed: Type: Kiwi, Weight: 4.859249812594946
Traversed: Type: Tomato, Weight: 4.915155758224849
Traversed: Type: Banana, Weight: 4.966555043577987
Traversed: Type: Kiwi, Weight: 4.969338821021524


Printing the post-order traversal
Traversed: Type: Kiwi, Weight: 4.969338821021524
Traversed: Type: Banana, Weight: 4.966555043577987
Traversed: Type: Tomato, Weight: 4.915155758224849
Traversed: Type: Kiwi, Weight: 4.859249812594946
Traversed: Type: Banana, Weight: 4.849541488248527
Traversed: Type: Tomato, Weight: 4.847156403059746
Traversed: Type: Apple, Weight: 4.743952143832523
Traversed: Type: Apple, Weight: 4.689654965283379
Traversed: Type: Apple, Weight: 4.658519644572135
Traversed: Type: Orange, Weight: 4.625294775272419
Traversed: Type: Tomato, Weight: 4.546460476028497
Traversed: Type: Kiwi, Weight: 4.540499450437838
Traversed: Type: Banana, Weight: 4.53176969188548
Traversed: Type: Tomato, Weight: 4.526667348325462
Traversed: Type: Banana, Weight: 4.433034496372054
Traversed: Type: Apple, Weight: 4.393777226918403
Traversed: Type: Apple, Weight: 4.391919428583659
Traversed: Type: Orange, Weight: 4.36635444379318
Traversed: Type: Tomato, Weight: 4.272392839694168
Traversed: Type: Orange, Weight: 4.153591707921256
Traversed: Type: Kiwi, Weight: 3.9930885812782018
Traversed: Type: Kiwi, Weight: 3.9629238331885324
Traversed: Type: Tomato, Weight: 3.91505462517807
Traversed: Type: Tomato, Weight: 3.826549862259843
Traversed: Type: Banana, Weight: 3.714749888189644
Traversed: Type: Tomato, Weight: 3.6568222763434206
Traversed: Type: Kiwi, Weight: 3.6566367557127104
Traversed: Type: Banana, Weight: 3.6494527648643906
Traversed: Type: Banana, Weight: 3.615339037449382
Traversed: Type: Orange, Weight: 3.545459485746505
Traversed: Type: Apple, Weight: 3.514259115351504
Traversed: Type: Tomato, Weight: 3.497931384921258
Traversed: Type: Banana, Weight: 3.4720359583562126
Traversed: Type: Kiwi, Weight: 3.421597330474709
Traversed: Type: Kiwi, Weight: 3.4113369395371054
Traversed: Type: Apple, Weight: 3.4067654081096292
Traversed: Type: Apple, Weight: 3.3261168784899335
Traversed: Type: Banana, Weight: 3.2401966619579925
Traversed: Type: Banana, Weight: 3.2250175222146633
Traversed: Type: Banana, Weight: 3.21651584121321
Traversed: Type: Banana, Weight: 3.1508667661022742
Traversed: Type: Kiwi, Weight: 3.130265580641745
Traversed: Type: Orange, Weight: 3.02213500791712
Traversed: Type: Apple, Weight: 2.901424898527876
Traversed: Type: Banana, Weight: 2.883294535298652
Traversed: Type: Apple, Weight: 2.873673933472279
Traversed: Type: Kiwi, Weight: 2.7912885879702385
Traversed: Type: Orange, Weight: 2.780001649154491
Traversed: Type: Orange, Weight: 2.757644307430845
Traversed: Type: Banana, Weight: 2.7429004129169074
Traversed: Type: Apple, Weight: 2.7179760646130386
Traversed: Type: Apple, Weight: 2.7092949536458164
Traversed: Type: Banana, Weight: 2.5591805544621793
Traversed: Type: Orange, Weight: 2.5568387709811633
Traversed: Type: Orange, Weight: 2.517329931945071
Traversed: Type: Banana, Weight: 2.465349052236099
Traversed: Type: Kiwi, Weight: 2.408573828682015
Traversed: Type: Banana, Weight: 2.4012979272659667
Traversed: Type: Apple, Weight: 2.3859195693200412
Traversed: Type: Tomato, Weight: 2.310589336413322
Traversed: Type: Tomato, Weight: 2.287438968525538
Traversed: Type: Kiwi, Weight: 2.213939203129497
Traversed: Type: Kiwi, Weight: 2.011793621529901
Traversed: Type: Banana, Weight: 1.9974965504311042
Traversed: Type: Orange, Weight: 1.9579096081143628
Traversed: Type: Orange, Weight: 1.9226762091089729
Traversed: Type: Apple, Weight: 1.9202813393056317
Traversed: Type: Tomato, Weight: 1.7502849810509313
Traversed: Type: Banana, Weight: 1.703457163967561
Traversed: Type: Orange, Weight: 1.6425177539231268
Traversed: Type: Banana, Weight: 1.6365611326426943
Traversed: Type: Apple, Weight: 1.6104335196184982
Traversed: Type: Kiwi, Weight: 1.5877722583775062
Traversed: Type: Kiwi, Weight: 1.5426974863764342
Traversed: Type: Orange, Weight: 1.415314546041357
Traversed: Type: Apple, Weight: 1.2596977062097159
Traversed: Type: Banana, Weight: 1.2295130239577738
Traversed: Type: Kiwi, Weight: 1.0340475191748726
Traversed: Type: Apple, Weight: 1.0097048804700366
Traversed: Type: Tomato, Weight: 0.9906677529489888
Traversed: Type: Orange, Weight: 0.9621352335043648
Traversed: Type: Tomato, Weight: 0.9570475745762608
Traversed: Type: Kiwi, Weight: 0.9482193843337194
Traversed: Type: Tomato, Weight: 0.9136235636337187
Traversed: Type: Banana, Weight: 0.8249611080979419
Traversed: Type: Orange, Weight: 0.7370861566279563
Traversed: Type: Apple, Weight: 0.6205068678131825
Traversed: Type: Apple, Weight: 0.603296674503539
Traversed: Type: Apple, Weight: 0.4859853412170728
Traversed: Type: Kiwi, Weight: 0.45564459240483524
Traversed: Type: Banana, Weight: 0.3572110962871161
Traversed: Type: Tomato, Weight: 0.3259901339116539
Traversed: Type: Apple, Weight: 0.3216606460346705
Traversed: Type: Apple, Weight: 0.30978149002689526
Traversed: Type: Kiwi, Weight: 0.27100642727895363
Traversed: Type: Apple, Weight: 0.24516328879201021
Traversed: Type: Apple, Weight: 0.12049892596510792
Traversed: Type: Banana, Weight: 0.09413408636637421
Traversed: Type: Orange, Weight: 0.07967274292009441
Traversed: Type: Banana, Weight: 0.006167454282033358