Guest User

Insert

a guest
May 11th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment