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

shz.core.queue.p.MinPQueue 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 MinPQueue extends RBBSTPQueue {
    private static final long serialVersionUID = 2530662136676032622L;

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

    public static  MinPQueue of(Comparator 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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy