Question: My code is not working. :( I was trying to make a heap that would help me get the top logn flyers. Algorithm HAS to

My code is not working. :( I was trying to make a heap that would help me get the top logn flyers. Algorithm HAS to be in O(n) time.

Please help in fixing the errors & proving that run time is O(n).

-----------------------------------------------------------------------------------------------

package A3;

import java.util.Scanner; import java.util.PriorityQueue; import java.util.Collections;

public class TamarindoAirlines { private static PriorityQueue Heap = new PriorityQueue<>(); public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter the number of flyers: "); int n = scan.nextInt(); int [] array = new int[n]; for (int i = 0; i < n; i++) { System.out.print("Enter the number of miles flown by flyer #"+ (i+1) + ": "); float miles = scan.nextInt(); array[i] = (int) (1/miles); } scan.close(); calcTopFlyers(array, n); } public static int[] calcTopFlyers(int[] array, int n) { int [] B = new int[n]; for (int i = 0; i < Math.log10(n); i++) { B[i] = Heap.remove(); } return B; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!