shz.core.queue.p.MinPQueue Maven / Gradle / Ivy
package shz.core.queue.p;
import java.util.Comparator;
public final class MinPQueue extends RBBSTPQueue {
private static final long serialVersionUID = 2530662136676032622L;
public MinPQueue(Comparator super E> comparator) {
super(comparator);
}
public static MinPQueue of(Comparator super E> comparator) {
return new MinPQueue<>(comparator);
}
@Override
public E peek() {
if (root == null) return null;
Node h = root;
while (h.left != null) h = h.left;
return h.e;
}
@Override
protected Node delTop(Node h) {
if (h.left == null) return h.right;
if (!isRed(h.left) && !isRed(h.left.left)) h = moveRedLeft(h);
h.left = delTop(h.left);
return balance(h);
}
}