title: Heap for a general Object
body: <p>I am writing a Heap (Max-Heap, meaning max element is root) class that can be used to "heapify" a given set of objects.
  I am aware of the general structure of this heap and also the various algorithms.
  Now for a general Object, comparison is not defined. So I need to define the comparison between two objects.
  My question is if this comparison function should be defined in the class heap or in the class Object? If I define it in class Heap then for every data structure that I use I need to rewrite the comparison function which is not efficient. This is because if I change the Object slightly I might end up changing the comparison at huge number of places.
  So how is this thing handled?
  Thank you.</p>
  
  <pre><code> class Object{
       int value;
       Object (int a) {
           value=a;
       }
  
       boolean isLessThan(Object a, Object b){
           if (a.value&lt;=b.value){
               return true;
           }
           else return false;
       }
   }
  
   class Heap{
       Object [] heap=new Object[1000];
       int size=0;
       Heap() {        
       }
  
       void HeapifyDownwards (int index){
           int left_child=2*index+1;
           int right_child=2*index+2;
  
           if (size&gt;right_child){
               // both right and left child exist
               Object right= heap[right_child];
               Object left= heap[left_child];
               Object node = heap[index];
  
               if ((isLessThanEqualTo(right,node)) &amp;&amp; (isLessThanEqualTo(left,node))){
                   return;
               }
           }
           else if (size==right_child){
               //only left child exists
           } 
           else {
               // no child exists
           }
       }
   }
  </code></pre>