
Insert
By: a guest on
May 11th, 2012 | syntax:
Java | size: 0.69 KB | hits: 17 | expires: Never
public void insert (BNode current, int value){
if(value<current.getValue())
{
if(current.getLeft_child()!=null)
{
current = current.getLeft_child();
insert(current, value);
}
else {
BNode newNode = new BNode(value);
current.setLeft_child(newNode);
System.out.println("Inserted " + value + " to the left of " + current.getValue());
}
}
else
{
if(current.getRight_child()!=null)
insert(current.getRight_child(), value);
else {
BNode newNode = new BNode(value);
current.setRight_child(newNode);
System.out.println("Inserted " + value + " to the right of " + current.getValue());
}
}
} //End of insert