Hello, I would like to ask is there any class connected with the Tree data structure in the Java Api, since I couldn't find one. I'm just starting to study the Binary Search Trees, the Heap data structure etc. As far as I could see until now, I will have to define my own classes when working with Trees... I mean, this is not what I like to do, defining classes like this all the time:
class TwoChildNode{
protected Object data;
protected TwoChildNode left,right;
public TwoChildNode(){
data = null;
left = right = null;
}
public TwoChildNode(Object d){
data = d;
left = right = null;
}
public void setLeft(TwoChildNode l){
left = l;
}
public void setRight(TwoChildNode r){
right = r;
}
public void setData(Object d){
data = d;
}
public TwoChildNode getLeft(){
return left;
}
public TwoChildNode getRight(){
return right;
}
public Object getData(){
return data;
}
public String toString(){
return ""+data;
}
}
public class BinaryTree {
TwoChildNode root; //sekoe drvo ima samo eden koren
public BinaryTree()
{
root=new TwoChildNode(); //kreiranje na koren
}
public boolean setRoot(Object o)
{
//ako veke korenot e postaven,nemoze da postavime nov
if(root.getData()!=null) return false;
else
root.setData(o);
return true;
}
What I mean is - is there any class like the LinkedList, or the ArrayList class that I will be able to use instead ? Thank for any answer.