Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Comparator;
- public class MedianHeap<K extends Comparable> extends BinaryHeap<K>{
- protected BinaryHeap minheap = new BinaryHeap();
- private Comparator<K> maxcomp;
- public MedianHeap(){
- this(new MaxComparator<K>());
- }
- public MedianHeap(MaxComparator<K> maxcomp){
- BinaryHeap maxheap = new BinaryHeap();
- this.maxcomp = maxcomp;
- }
- public boolean isEmpty(){
- return false;
- }
- public int size(){
- return 0;
- }
- /*
- private void rebalance(){
- //perhaps you'd use a helper method like this...
- }
- */
- public void insert(K k){
- minheap.insert(k);
- }
- public K removeMedian(){
- if(isEmpty()) return null;
- K result = minheap.removeMin();
- return result;
- }
- public K median(){
- return null;
- }
- public static void main(String[] args){
- MedianHeap lowers = new MedianHeap();
- lowers.insert(1);
- System.out.println(lowers.minheap.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement