0
BSTree插入節點:誤差BSTree插入
import java.util.*;
import java.io.*;
public class BSTree {
private Node root;
private int size;
public BSTree(){root = null; size = 0;}
public Node root(){return root;}
public boolean isEmpty(){return root == null;}
public int size(){return size;}
public void insert(String s){
root = new Node (s, root, null, null);
size++;
}
private void insert(String s,Node node){
if (root.setLeft() < 0 || root.hasLeft() > 0) // Currrently I have error on this line of code
root = new Node (s, root, node, node);
else {
Node cursor = root;
Node next = cursor.getRight();
while (next != null && next.compareTo(s) <= 0) { // I also having error on the next.compareTo(s).
cursor = next;
next = next.getRight();
}
cursor.setRight(new Node(s, next, next, next));
}
size++;
}
誰能幫我解決這個錯誤嗎? 我是BSTree的新手,因此我不確定哪裏出了問題。但是我的Node類沒有問題。
謝謝:)
什麼是實際錯誤?另外,爲什麼你的Node構造函數將其實例化爲一個參數? – Mike
「Node」類定義在哪裏? –