小编Bub*_*Tea的帖子

Collections.sort()错误

我试图根据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)

java compareto

1
推荐指数
1
解决办法
8551
查看次数

在任何 n 元素树中最多有天花板 (n/2^(h+1)) 个高度为 h 的节点

参考来自 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 个节点。

在此处输入图片说明

algorithm tree binary-tree binary-search-tree

1
推荐指数
1
解决办法
2458
查看次数