This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class MaintainMedianDataStructure { | |
| PriorityQueue<Double> lower = new PriorityQueue<Double>(Collections.reverseOrder()); | |
| PriorityQueue<Double> higher = new PriorityQueue<Double>(); | |
| public void insert(double data) { | |
| if (lower.size() == 0 || higher.size() == lower.size()) { | |
| lower.offer(data); | |
| } else { | |
| lower.offer(data); |