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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started