Question: can someone please explain why my Java code is not printing the value shown in the picture. This is my code:import java.util.Collections; import java.util.PriorityQueue; import
can someone please explain why my Java code is not printing the value shown in the picture. This is my code:import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main
static Scanner in;
Method to calculate med of stream
public static void printMedianint n
max heap to store the smaller half elements
PriorityQueuesmaller new PriorityQueue
CollectionsreverseOrder;
minheap to store the greater half elements
PriorityQueue greater new PriorityQueue;
int data innextInt; first input
smaller.adddata;
double med data; first number itself a median
System.out.printlnmed;
forint i; i greater.size
ifx med
greater.addsmallerremove;
smaller.addx;
else
greater.addx;
med doublesmallerpeekgreater.peek;
Case both heaps are balanced
else if smallersize greater.size
if x med
smaller.addx;
med doublesmallerpeek;
else
greater.addx;
med doublegreaterpeek;
Case the right side heap has more elements
else if smallersize greater.size
if x med
smaller.addgreaterremove;
greater.addx;
else
greater.addx;
med doublesmallerpeekgreater.peek;
System.out.printlnmed;
Driver code
public static void mainString args
TODO Autogenerated method stub
in new ScannerSystemin; Creates a Scanner object
int n innextInt;
printMediann;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
