주어진 클래스를 사용하여 순서가 지정된 사전을 기반으로 AVL 트리를 구현하려고하지만 해당 생성자에 문제가 있습니다. 이는 AVL 클래스입니다 :Java AVL 트리 생성자 구현
public class AVLTree implements AVLTreeInterface {
private Comparator comp;
private AVLnode avlentry;
private AVLnode root;
private int size;
/*
* Constructor which initializes AVL tree to hold 0 entries
* Sets comparator object to one provided in input
* "Empty" tree consists of 1 external node, as the root, that does not hold any entries
*/
public AVLTree(Comparator inputComparator){
DictEntry entry = new DictEntry(0,0);
root = new AVLnode(entry,avlentry,avlentry,avlentry);
comp = inputComparator;
}
그리고 그것은 가장 큰 문제는 AVLnode resetHeight 예외의 예외가 작동하지 않는 것이이 클래스 AVLnode
//package a3;
import java.lang.*;
public class AVLnode implements Position{
private AVLnode parent; // reference to the parent node
private AVLnode left; // reference to the left child
private AVLnode right; // reference to the right child
private DictEntry entry; // reference to the entry stored at the node
private int height; // height of the node for checking balance-height property
public AVLnode(DictEntry inputEntry, AVLnode inputParent, AVLnode inputLeft, AVLnode inputRight)
{
entry = inputEntry;
parent = inputParent;
left = inputLeft;
right = inputRight;
height = 0;
if (left != null) height = Math.max(height,1+left.getHeight());
if (right != null) height = Math.max(height,1+right.getHeight());
}
public AVLnode parent(){ return parent;}
public AVLnode left() {return left;}
public AVLnode right() {return right;}
public int getHeight() { return height; }
public DictEntry getEntry() { return entry; }
public void setParent(AVLnode newParent){ parent = newParent; }
public void setLeft(AVLnode newLeft) {left = newLeft;}
public void setRight(AVLnode newRight) { right = newRight; }
public void setEntry(DictEntry newEntry) { entry = newEntry; }
public Object element(){return entry;}
public void resetHeight() throws AVLtreeException{
if (left == null || right == null) throw new AVLtreeException("Attempt to update height for external node ");
height = 1+Math.max(left.getHeight(),right.getHeight());
}
}
을 기반으로하고, 어떻게 뿌리를 추가했는지 모르겠다.
EDIT : 1 오류가 발견되었습니다. 파일 : C : \ xxxxxxxxxxxx x \ AVLnode.java [line : 33] 오류 : AVLtreeException 클래스의 생성자 AVLtreeException을 특정 유형에 적용 할 수 없습니다. 필요하지 않습니다 : 인수 발견 : java.lang.String의 이유 : 실제와 형식 인수 목록이
길이
에 차이가/**
* Auto Generated Java Class.
*/
import java.lang.*;
public class AVLtreeException extends Throwable {
/* ADD YOUR CODE HERE */
}
감사를 받고 오류 메신저입니다!