Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Comparator;
  3. public class MedianHeap<K extends Comparable> extends BinaryHeap<K>{
  4.     protected BinaryHeap minheap = new BinaryHeap();
  5.     private Comparator<K> maxcomp;
  6.     public MedianHeap(){
  7.         this(new MaxComparator<K>());
  8.     }
  9.     public MedianHeap(MaxComparator<K> maxcomp){
  10.         BinaryHeap maxheap = new BinaryHeap();
  11.         this.maxcomp = maxcomp;
  12.     }
  13.     public boolean isEmpty(){
  14.         return false;
  15.     }
  16.     public int size(){
  17.         return 0;
  18.     }
  19.  
  20.     /*
  21.     private void rebalance(){
  22.         //perhaps you'd use a helper method like this...
  23.     }
  24.     */
  25.  
  26.     public void insert(K k){
  27.         minheap.insert(k);
  28.     }
  29.     public K removeMedian(){
  30.         if(isEmpty()) return null;
  31.         K result = minheap.removeMin();
  32.         return result;
  33.     }
  34.     public K median(){
  35.         return null;
  36.     }
  37.     public static void main(String[] args){
  38.         MedianHeap lowers = new MedianHeap();
  39.         lowers.insert(1);
  40.  
  41.        
  42.         System.out.println(lowers.minheap.toString());
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement