priority-queue

    1熱度

    1回答

    我不知道如何在java中使用優先級隊列,就像在C++中一樣。 在C++中,我們可以這樣說: priority_queue<object*, vector<object*>, compareClass> 所以,當我們有課是這樣的: class Foo{ public: int number1; int number2 Foo(){}; }; 我們可以用兩種不

    0熱度

    1回答

    我已經給了一個實現優先級隊列的類,使用函數來評估優先級。 class PriorityQueueWithFunction(PriorityQueue): """ Implements a priority queue with the same push/pop signature of the Queue and the Stack classes. This is

    -1熱度

    1回答

    我有一個名爲Pair的預定義類,其中包含一個鍵和一個值。我根據每對的價值的自然順序將它們存儲在PriorityQueue中。當我改變Pair中的一個值然後出隊時,我期望沒有發生。測試代碼如下。請幫忙。我感到困惑! import java.util.*; public class Test { static class Pair { int key; int va

    -1熱度

    1回答

    我是堆和PQ概念的新手。所以我試圖使用PQ使用最小堆實現堆棧。 我想實現以下方法: 彈出 彈出 的isEmpty 頂部 大小 下面是代碼: import java.util.*; import java.lang.System; public class StackUsingMinPriorityQueue{ static int a[] = {3,7,2,11,9,4};

    0熱度

    1回答

    我爲PriorityQueue編寫了一個比較器,以便根據HashMap中ArrayList中的第一個值給出最小值。 我的問題是,在我的程序的其餘部分,我需要更新/更改ArrayList中的第一個值。我不確定如何做到這一點,以確保優先隊列總是給我基於更新的正確結果? 感謝 public class MyComparator implements Comparator<Integer>{ H

    0熱度

    2回答

    var LocalFile = "xxx.json" var Delta = false var priority = DISPATCH_QUEUE_PRIORITY_DEFAULT init(){ priority = DISPATCH_QUEUE_PRIORITY_HIGH } init(_:Bool){ Delta = true priority

    -1熱度

    1回答

    我正在研究優先級隊列(堆),並認爲我有一個良好的基礎。我認爲我的方法大部分都是有意義的,但在我的bubbleDown和deleteMin方法上真的很掙扎。 public class Heap { private int n; private Node[] s; public Heap() { s = new Node[128]; n =0;

    -1熱度

    1回答

    我有一個包含1000個字符的文件。我把這個文件存儲起來並存儲到一個字符串中。 ()。distinct()。count() - 我的字符串中唯一字符的數量 我需要一個char []字符,長度爲str.chars將我的String str中的每個唯一字符存儲到我的char數組中 - 字母 我還需要存儲String str中每個字符的頻率它可能是另一個數組。 字母數組中每個項目的索引必須與該頻率數組中元

    0熱度

    4回答

    我正在使用priority_queue來解決問題。 我打算以下面的方式聲明我的節點。 struct node{ int x, y, val; node(int _x, int _y, int _val){ x = _x; y = _y; val = _val; } bool operator < (const

    0熱度

    1回答

    我想實現一個優先級隊列,它將按照其大小順序排列HashSets(即最小的HashSets將具有最高的優先級)。 我該如何在Java中實現它? 以下是我嘗試按優先級編號(最高優先級)成功訂購HashSets的次數。 我的主要方法: System.out.print("Enter size of priority queue: "); int inputSize = scanner.ne