I’m trying to create a b-tree class that implements the collection interface shown below. The Issue here is that the add method takes in an object and my node classes setleftNode takes in a Node of a generic type “T”. Thus I’m getting method cant be applied to given type error when compiling. :
B-Tree Class:
public class BST<T> implements Collection<T>{
private Node<T> _root;
private Node<T> _current;
private Random _rnd = new Random();
public BST(Node<T> root) {
_root = root;
}
public Node<T> getRoot(){
return _root;
}
@Override
public Iterator iterator() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean add(Object e) {
if (this._root != null){
if(this._root.getLeftNode() == null){
this._root.setLeftNode(e);
return true;
}
}
return false;
}
Node Class:
public class Node<T>{
private T _value;
private Node<T> _left;
private Node<T> _right;
public Node (T value){
_value = value;
}
public T getValue(){
return _value;
}
public void setLeftNode(Node<T> node){
_left= node;
}
public void setRightNode(Node<T> rNode){
_right = rNode;
}
public Node getRightNode(){
return _right;
}
public Node getLeftNode(){
return _left;
}
}
If
BST<T>implementsCollection<T>it should haveadd(T e). And insidesetLeftNode(new Node<T>(e))):