Don't like ads? PRO users don't see any ads ;-)
Guest

Insert

By: a guest on May 11th, 2012  |  syntax: Java  |  size: 0.69 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public void insert (BNode current, int value){
  2.                
  3.         if(value<current.getValue())
  4.         {
  5.                 if(current.getLeft_child()!=null)
  6.                 {
  7.                         current = current.getLeft_child();
  8.                         insert(current, value);
  9.                 }
  10.                 else {
  11.                        
  12.                 BNode newNode = new BNode(value);
  13.                 current.setLeft_child(newNode);
  14.                 System.out.println("Inserted " + value + " to the left  of " + current.getValue());
  15.                
  16.                
  17.                        
  18.                 }
  19.                 }
  20.        
  21.         else
  22.         {
  23.                 if(current.getRight_child()!=null)
  24.                         insert(current.getRight_child(), value);
  25.                
  26.                 else {
  27.                        
  28.                         BNode newNode = new BNode(value);
  29.                         current.setRight_child(newNode);
  30.                         System.out.println("Inserted " + value + " to the right of " + current.getValue());
  31.                 }
  32.                
  33.         }
  34.         } //End of insert