Answers for "kth largest element max heap code java"

8

max heap java

import java.util.PriorityQueue;

public class MaxHeapWithPriorityQueue {

    public static void main(String args[]) {
        // create priority queue
        PriorityQueue<Integer> prq = new PriorityQueue<>(Comparator.reverseOrder());

        // insert values in the queue
        prq.add(6);
        prq.add(9);
        prq.add(5);
        prq.add(64);
        prq.add(6);

        //print values
        while (!prq.isEmpty()) {
            System.out.print(prq.poll()+" ");
        }
    }

}
Posted by: Guest on August-02-2020
0

K Largest Elements Heap

1. You are given a number n, representing the size of array a.2. You are given n numbers, representing elements of array a.3. You are given a number k.4. You are required to find and print the k largest elements of array in increasing order.
Posted by: Guest on May-14-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language