Is there a Heap in java?

后端 未结 6 1993
一整个雨季
一整个雨季 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:51

    In Java PriorityQueue can be used as a Heap.

    Min Heap

    PriorityQueue minHeap = new PriorityQueue<>();
    

    Max Heap:

    PriorityQueue maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
    

提交回复
热议问题