Hello, I have to do Binary Search Tree. I found on internet a lot of versions, but i need it just simple. First time, I need help with method insert.
My code:
public class BinarySearchTree { private Node root; private Node parent; private Node node; public boolean isEmpty() { return root==null ; } public void insert(int number) { if(root==null) { Node newNode = new Node(); newNode.setData(number); root=newNode; } } public void remove(int) { } public boolean contains(int) { return; } }
public class Node { private Node left; //left children private Node right; //right children private Node parent; private int data; public void setLeft(Node left) { this.left=left; } public Node getLeft() { return left; } public void setRight(Node right) { this.right=right; } public Node getRight() { return right; } public void setParent(Node parent) { this.parent=parent; } public Node getParent() { return parent; } public void setData(int data) { this.data=data; } public int getData() { return data; } }