Создание итеративной вставки для бинарного дерева поиска - PullRequest
0 голосов
/ 30 января 2020

Привет, мне нужно создать метод итеративной вставки для данного класса дерева;

public class Tree {
  private int value ;
  private Tree lhs ; // left child
  private Tree rhs ; // right child

  Tree ( int value ) {
    this . value = value ;
  }
...
}

Мой метод выглядит так:

public class Tree {
 private int value;
 private Tree lhs; // left child
 private Tree rhs; // right child

  Tree(int value) {
    this.value = value;
  }

  public void insert(int insertValue) {
    while (this.value != null) {
      if(insertValue < value)
         if(this.lhs == null) {
           lhs = new Tree(insertValue);
           break;
         }
         else 
           lhs = this.lhs;
       else
         if(this.rhs == null) {
           rhs = new Tree(insertValue);
           break;
         }
         else rhs = this.rhs;
     }
   }
}

Компилятор говорит:

Tree.java:20: error: bad operand types for binary operator '!=' while (this.value != null)
                                                                                  ^
firt type: int
second type: <null>
1 error
...