PQueue.java

public class PQueue extends ArrayStore {
   COMPARER comparer = new DefaultComparer();
   public PQueue() {};
   public PQueue(COMPARER c) {this.comparer = c;};
   public void add (Object o) {
      growTo(length+1);
      array[length] = o;
      int i=length; 
      Object tmp;
      boolean done = false;
      while (!done & i > 0) {
         if(comparer.compare(array[i-1],array[i]) == 1) {
            tmp = array[i];
            array[i] = array[i-1];
            array[i-1] = tmp;
            i--;
         } else {done = true;}
      };
      length++;
   }
   public String toString () {
      StringBuffer ws = new StringBuffer();
      ws.append("Anfang->");
      for (int i = length-1; i >= 0; i--) {
         ws.append(array[i]+" ");
      };
      ws.append("<-End");
      return ws.toString();
   }
   public STORE map(FUNCTION f) {
      MapFunction mf = new MapFunction(new PQueue(comparer),f);
      execute(mf);
      return mf.store();
   }
}

class DefaultComparer implements COMPARER {
   public int compare(Object o1, Object o2) {
      return ((ORDER)o1).compare(o2);
   }
}


On to COMPARER.java Part of store
Hubert Baumeister
June 21, 1997

Imprint | Data Protection