Is there a Heap in java?

后端 未结 6 2001
一整个雨季
一整个雨季 2021-01-31 13:00

I am porting a C++ library to Java and I need a heap data structure. Is there a standard implementation or will I need to do it myself?

6条回答
  •  庸人自扰
    2021-01-31 13:54

    No as such there isn't but you can use Priority Queue as a Heap. Its officially told by Oracle to use Priority Queue as a Heap you can also refer to this link for further clarification.

    PriorityQueue MinHeap = new PriorityQueue<>();
    
    PriorityQueue MaxHeap = new PriorityQueue<>(Comparator.reverseOrder());
    

提交回复
热议问题