자바에서 내 자신의 바이너리 검색 트리를 쓰려고합니다. 나는 모든 메서드를 작성했으며, 이제는 메서드를 테스트 할 프로그램을 작성하려고합니다.바이너리 검색 트리, 삽입 방법이 컴파일되지 않습니다
그러나 "삽입"방법을 구현하려고하면 컴파일되지 않으며 이유가 없습니다. 그것이
public class myTreeNode {
public myTreeNode() {
}
public Comparable data ;
public myTreeNode leftchild;
public myTreeNode rightchild;
public myTreeNode parent;
public void insert(Comparable d) {
//if less than
//does left exist? if it doesnt, make it, give it d
//if it exists call insertrecursive on rightchild
if(d.compareTo(data) <= 0) {
if(leftchild != null) {
leftchild.insert(d);
} else {
leftchild = new myTreeNode();
leftchild.data = d;
leftchild.parent = this;
}
} else {
if(rightchild != null) {
rightchild.insert(d);
} else {
rightchild = new myTreeNode();
rightchild.data = d;
rightchild.parent = this;
}
}
}
...more code...
}
: 같은
public interface myBST {
public void insert(Comparable x);
public void delete(Comparable x);
public boolean lookup(Comparable x);
public void printPreOrder();
public void printInOrder();
public void printPostOrder();
}
마지막으로, myTreeNode 보이는 : myBST의 모습,
public class BST implements myBST {
private myTreeNode root;
public BST() {
}
public void insert(Comparable x) {
if(root == null) {
root = new myTreeNode();
root.data = x;
} else if (!lookup(x)) {
root.insert(x);
}
}
...more code...
}
과 :
public class lab05driver {
public static void main(String[] args) {
BST q = new BST();
int a = 5;
String b = "jed";
double c = 1.8;
char d = 'r';
boolean e = false;
int f = 35;
String g = "yay";
double h = 2.1;
char i = 'i';
boolean j = true;
Integer k = 5;
q.insert(k);
}}
내 BST 클래스는 다음과 같습니다 lab05dr의 "q.insert (k)"에 오류가 발생했습니다. 나. 모든 도움/제안 크게 감사하겠습니다 ... ~~~~~ 수정 : 죄송합니다 내가 잘못 복사 ... 주 방법 및 정수 k입니다 정수 ... 오류 메신저 명령 행을 얻는 것은 다음과 같습니다 : 경고 : 원시 타입의 구성원으로서 compareTo (T)의 체크되지 않은 호출이 선택되었습니다. java.lang.Comparable
숙제 확인
을해야 하는가? 컴파일러 출력이란 무엇입니까? – esej
이 줄에서도 오류가 없습니다 -'Integer k = "test"'? – Dukeling