comparator

    1熱度

    2回答

    我正在嘗試使用Collections.sort()對List<Point2D>點進行排序。我相信我正確設置了這個比較器。無論如何,這是拋出一個錯誤說:The method sort(List<T>, Comparator<? superT>) in the type Collections is not applicable for the arguments (List<Point2D>, ne

    1熱度

    2回答

    我在尋找一個「動態比較器」,根據運行時參數給出比較結果。 這是一個比較器,根據它們到輸入參數x的距離比較兩個整數。 struct leq { bool operator()(const int a, const int b, const int x) { return abs(a-x) <= abs(b-x); } }; 希望用它來實現下列插入到含有一個整數

    0熱度

    1回答

    我寫這個的jsfiddle測試AngularJS比較,但比較不工作: my jsFiddle Comparator 看來,我的比較功能wiggleSort將不會被調用: <span data-ng-repeat="myItem in myArray | orderBy:'start':false:wiggleSort" 我做錯了什麼?

    1熱度

    6回答

    假設我有以下的compareTo: public int compareTo(RandomClass o) { if (this.value() < o.value()) { return -1; } else if (this.value() > o.value()) { return 1; } else { return 0;

    3熱度

    3回答

    首先,請讓我明確一點,我受API設計的限制,所以請不要更改API,但是可以添加私有函數。 public class Point implements Comparable<Point> { public Point(int x, int y) // constructs the point (x, y) public void draw() // draws

    2熱度

    2回答

    我正在學習Comparator接口來解決分數揹包問題。行a和b中的兩個數組表示3個值 - 權重對 - (60,20),(100,50),(120,30)。比較器應該根據v [i]/w [i]的比值對arr []進行排序。但是,下面的代碼給了我奇怪的錯誤: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3

    1熱度

    3回答

    我有一個字符串地圖的字符串,我想排序地圖根據他的價值爲凱F,但我的代碼沒有這樣做。請指教。 Map<String, String> h = null; Map<String, String> h1 = null; Map<String, String> h2 = null; listSummaryMap = new ArrayList<Map<String, Stri

    0熱度

    3回答

    class IntegerComparator implements Comparator<Integer> { @Override public int compare(Integer o1, Integer o2) { if(o1 < o2) return 1; else if(o1 > o2) return -1; else

    -3熱度

    1回答

    如何最小化使用java的比較器方法8 實際上,我通過包含工作日的工作日列表,其中包含我需要按日期升序和降序排列日期的工作日清單 我需要日期按升序 private List<WorkingDays> workingDaysDateSortDesc(List<WorkingDays> workingDays) { Collections.sort(workingDays.get(0).get

    0熱度

    1回答

    好Day- 我的工作中,我已經指令來創建一個命名爲void sortByAthleteNames()方法,該方法將執行以下任務的任務: 排序列表運動員用名字和姓氏對象。此方法調用在排序類中定義的類型的方法,使用AthleteNameComparator類的對象作爲其第二個參數 排序類具有以下實現: public class Sorts { public static void sort