PQueue1.pizza

public class PQueue1<T> extends StoreWithArray<T> {

   COMPARER<T> comparer;

   protected PQueue1() {};

   public PQueue1(COMPARER<T> c) {this.comparer = c;};

   public void add (T o) {
      growTo(length+1);
      array[length] = new ObjectWrapper(o);
      int i=length; 
      ObjectWrapper<T> tmp;
      boolean done = false;
      while (!done & i > 0) {
         if(comparer.compare(array[i-1].object,array[i].object) == -1) {
            tmp = array[i];
            array[i] = array[i-1];
            array[i-1] = tmp;
            i--;
         } else {done = true;}
      };
      length++;
   }

//   public void addAll(T[] oa) {super.addAll(oa);}

   public String toString () {
      StringBuffer ws = new StringBuffer();
      ws.append("Anfang->");
      for (int i = length-1; i >= 0; i--) {
         ws.append(array[i].object+" ");
      };
      ws.append("<-End");
      return ws.toString();
   }
}


On to PQueue2.pizza Part of Priority Queues mit Pizza
Andreas Podelski, Abdelwaheb Ayari, Hubert Baumeister
February 25, 1997

Imprint | Data Protection