All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.core.queue.p.MaxPQueue Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
package shz.core.queue.p;

import java.util.Comparator;

public final class MaxPQueue extends RBBSTPQueue {
    private static final long serialVersionUID = 7993867654979754324L;

    public MaxPQueue(Comparator comparator) {
        super(comparator);
    }

    public static  MaxPQueue of(Comparator comparator) {
        return new MaxPQueue<>(comparator);
    }

    @Override
    public E peek() {
        if (root == null) return null;
        Node h = root;
        while (h.right != null) h = h.right;
        return h.e;
    }

    @Override
    protected Node delTop(Node h) {
        if (isRed(h.left)) h = rotateRight(h);
        if (h.right == null) return h.left;
        if (!isRed(h.right) && !isRed(h.right.left)) h = moveRedRight(h);
        h.right = delTop(h.right);
        return balance(h);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy