小编Fra*_*eek的帖子

索引优先级队列的混淆

我已经了解了优先级队列.但是当涉及到索引优先级队列时,我对某些方法的实现有点困惑,例如change(int k,Item item)delete(int i).

change(int k,Item item)是将与k关联的项目更改为item

delete(int i)是删除k及其关联项

public void changeKey(int i, Key key) {
        if (i < 0 || i >= maxN) throw new IndexOutOfBoundsException();
        if (!contains(i)) throw new NoSuchElementException("index is not in the priority queue");
        keys[i] = key;
        swim(qp[i]);
        sink(qp[i]);
    }

public void delete(int i) {
        if (i < 0 || i >= maxN) throw new IndexOutOfBoundsException();
        if (!contains(i)) throw new NoSuchElementException("index is not in the priority queue");
        int index = qp[i];
        exch(index, …
Run Code Online (Sandbox Code Playgroud)

java algorithm priority-queue

0
推荐指数
1
解决办法
3030
查看次数

标签 统计

algorithm ×1

java ×1

priority-queue ×1