简体   繁体   中英

Compile-time error in implementation of SearchTree

MyProg.java:44: error: Type mismatch: cannot convert from void to SearchTree

SearchTree nTree = nTree.insert(value);
                   ^^^^^^^^^^^^^^^^^^^

SearchTree.java:18: error: Type mismatch: cannot convert from void to int[] value = Arrays.sort(value);

package ab12;
public class MyProg {
public static void main(String[] args) {
    QueueScheduler q = new QueueScheduler();
    int c = 0;
    for (int i = 0; i < 10; i++) {
        q.dynQueue[c].put(i);
        if (c == 2) {
            c = -1;
        }
        c++;
    }   
    Out.println("1. Random");
    Out.println(q.getRandom());
    Out.println(q.getRandom());
    Out.println(q.getRandom());
    Out.println("2. Priority");
    Out.println(q.getPriority());
    Out.println(q.getPriority());
    Out.println("3. RoundRobin");
    Out.println(q.getRoundRobin());
    Set set = new Set();
    Set other = new Set();
    String e = "Hallo";
    String e2 = "H.";
    String e3 = "red";
    String e4 = "blue";
    String e5 = "light";
    set.add(e);
    set.add(e2);
    set.add(e3);
    set.remove(e);
    other.add(e2);
    other.add(e3);
    other.add(e4);
    other.add(e5);
    set.union(other);
    set.difference(other);
    set.isSubsetOf(other);
    int value [] = new int[]{1, 3, 5, 7, 9, 13, 18, 19, 21};
    SearchTree nTree = nTree.insert(value);
    int s = nTree.sum();
    int num = nTree.numberOfLeafs();



     }
}

The error gives you all the information you need -- you are trying to assign the result of a method call that returns void to a SearchTree . The insert method will not return the tree it was invoked on.

I'm not sure what your intent actually is here. If you're declaring SearchTree for the first time, then you won't be able to call a method on it in the same statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM