PQueue.java
public class PQueue extends StoreWithArray {
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();
}
}
class DefaultComparer implements COMPARER {
public int compare(Object o1, Object o2) {
return ((ORDER)o1).compare(o2);
}
}
On to Main.java Part of Priority Queues mit Java
Andreas Podelski, Abdelwaheb Ayari, Hubert Baumeister
February 25, 1997
Imprint | Data Protection