J'essaye d'implémenter une arborescence AVL basée sur un dictionnaire ordonné avec les classes qui m'ont été données, mais j'ai des problèmes avec le constructeur. Ceci est la classe AVL:Java AVL tree Constructeur Implémentation
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;
}
Et il est basé sur cette classe 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());
}
}
Le principal problème est que l'exception à l'exception AVLnode resetHeight ne fonctionne pas, et Je ne suis pas sûr que c'est à cause de la façon dont j'ajoute la racine
EDIT: 1 erreur trouvée: fichier: C: \ xxxxxxxxxxxx x \ AVLnode.java [ligne: 33] Erreur: le constructeur AVLtreeException dans la classe AVLtreeException ne peut pas être appliqué à des types donnés; requis: aucun argument trouvé: java.lang.String raison: listes d'arguments réels et formels diffèrent de longueur
est-im d'erreur se
/**
* Auto Generated Java Class.
*/
import java.lang.*;
public class AVLtreeException extends Throwable {
/* ADD YOUR CODE HERE */
}
Merci!