public class TreeSet { private TreeSet rightChild = null; // initialily this is null private TreeSet leftChild = null; // initiali this is null private Type value = null; // no value assigned yet public TreeSet(Type valoare) { this.value = valoare; } public TreeSet getRight() { return this.rightChild; } public TreeSet getLeft() { return this.leftChild; } public Type getValue() { return this.value; } public void addNewNode(TreeSet value) { if(this.leftChild == null && this.rightChild == null) { // am ajuns la frunza, adaugam valoarea // like Potolea (<3) if(value.getValue().compareTo(this.getValue()) == -1) { // daca e mai mica this.leftChild = value; } else if(value.getValue().compareTo(this.getValue()) == 1) { // daca e mai mare this.rightChild = value; } } else { if(value.getValue().compareTo(this.getValue()) == -1) { // daca e mai mica this.getLeft().addNewNode(value); } else if(value.getValue().compareTo(this.getValue()) == 1) { // daca e mai mare this.getRight().addNewNode(value); } } } }