用java实现AVL二进制搜索树

时间:2015-10-29 18:08:55

标签: java binary-search-tree

我应该将BST作为家庭作业来实现并破译隐藏的消息"。我提供了DataElement.java用于隐藏的消息,但我不确定它是如何工作的。看起来BSTTest文件来自:

public class DataElement<T> implements Comparable<DataElement<T>> {
    private T value;
    private Integer weight;

    public DataElement(T t, int i) {
        this.value = t;
        this.weight = new Integer(i);

@Override
    public int compareTo(DataElement<T> o) {
        return this.weight.compareTo(o.weight);
    }

    public String toString() {
        return value.toString();
    }
}

然后,我给了测试课。但我不确定如何解释重量,如果这是正确的措辞。例如:

public class BSTTest {

public static void main(String[] args) throws Exception {

        BinarySearchTree<DataElement<String>> root = new BinarySearchTree<DataElement<String>>(
        new DataElement<String>("u", 1782168893));
        root = root.insert(new DataElement<String>("A", -2138157432));
        root = root.insert(new DataElement<String>("e", 1219590329));
        root = root.insert(new DataElement<String>("z", -1205207264));
        root = root.insert(new DataElement<String>("e", 1147267944));
        root = root.insert(new DataElement<String>("A", 1534456190));
        root = root.insert(new DataElement<String>(" ", 963753082));
        root = root.insert(new DataElement<String>("t", -343169896));
        root = root.insert(new DataElement<String>("h", -719426805));

等等......那么参数中大+数字的意义是什么?

很抱歉,如果我不是Java,那我只是想找个地方开始。如果我不确定它是如何工作的,我就无法实现树。提前谢谢!

0 个答案:

没有答案
相关问题