我试图根据Class A的int r对B类中名为BinOrder的类型A进行排序.
但是我收到了Collections.sort(BinOrder)行的错误;
The method sort(List<T>) in the type Collections is not applicable for the arguments (ArrayList<A>)
Run Code Online (Sandbox Code Playgroud)
A类:
public class A{
int s;
int r;
public A(int si, int ri) {
s=si;
r= ri;
}
}
Run Code Online (Sandbox Code Playgroud)
B级:
import java.util.ArrayList;
import java.util.Collections;
public class B implements Comparable<A> {
public Iterator<A> randomMethodName(int a) {
ArrayList<A> BinOrder = new ArrayList<A>();
A a = new A(1,3)
A a2 = new A(1,4)
BinOrder.add(a);
BinOrder.add(a2);
}
// sort array in increasing order of r
Collections.sort(BinOrder); …Run Code Online (Sandbox Code Playgroud) 参考来自 Intro to Algorithms, pg 157。图像有 10 个节点,树的高度为 3。
我的问题是当 h=1 时这如何成立?
天花板(n/2^(h+1))=天花板(10/2^(1+1))=天花板(10/4)=天花板(2.5)=3个节点。但是 h=1 有 4 个节点。
