Code example for Comparator

Methods: compare

0
  /** perform element comaprisons using comparator or natural ordering **/ 
  protected int compare(Object a, Object b) {
    if (cmp_ == null) 
      return ((Comparable)a).compareTo(b);
    else 
      return cmp_.compare(a, b);
  } 
 
 
  // indexes of heap parents and children 
  protected final int parent(int k) { return (k - 1) / 2;  }
  protected final int left(int k)   { return 2 * k + 1; }
  protected final int right(int k)  { return 2 * (k + 1); }
 
  /** 
   * insert an element, resize if necessary 
   **/ 
  public synchronized void insert(Object x) {
    if (count_ >= nodes_.length) {
      int newcap =  3 * nodes_.length / 2 + 1;
      Object[] newnodes = new Object[newcap];