Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TreeSet <Type extends Comparable>{
- 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);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement