Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment