/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.datastructure.queue;

/**
 * @author cwenao
 * @version $Id IndexMinPQ.java, v 0.1 2017-09-02 23:33 cwenao Exp $$
 */
public class IndexMinPQ {
}

@@ -101,18 +101,83 @@
 queue;%0A%0A
-/*
+import java.util.Iterator;%0A%0A/** %E7%B4%A2%E5%BC%95%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%EF%BC%9A%E5%9C%A8%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%E7%9A%84%E5%9F%BA%E7%A1%80%E4%B8%8A%E5%8A%A0%E4%B8%8A%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%E4%B8%AD%E5%80%BC%E5%9C%A8qp%E4%B8%AD%E5%AF%B9%E5%BA%94%E7%9A%84%E7%B4%A2%E5%BC%95%0A 
 *%0A * @au
@@ -289,9 +289,1464 @@
 inPQ
- %7B
+%3CT extends Comparable%3E implements Iterable%7B%0A%0A    private int maxLen; //PQ%E7%9A%84%E6%9C%80%E5%A4%A7%E9%95%BF%E5%BA%A6%0A    private static final int DEFAULT_MAX_LEN = 20;%0A    private int len; //PQ%E9%95%BF%E5%BA%A6%0A    private int pq%5B%5D; // %E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%0A    private int qp%5B%5D; // %E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%E5%80%BC%E6%98%A0%E5%B0%84%E5%88%97%E8%A1%A8%0A    private T%5B%5D keys; // %E7%9C%9F%E5%AE%9E%E5%85%83%E7%B4%A0%E9%98%9F%E5%88%97%0A%0A    public IndexMinPQ() %7B%0A        this(DEFAULT_MAX_LEN);%0A    %7D%0A%0A    public IndexMinPQ(int maxLen) %7B%0A        this.maxLen = maxLen;%0A        pq = new int%5BmaxLen + 1%5D;%0A        qp = new int%5BmaxLen + 1%5D;%0A        keys = (T%5B%5D) new Comparable%5BmaxLen + 1%5D;%0A        len = 0;%0A%0A        for (int i=0;i%3C=maxLen;i++) %7B%0A            qp%5Bi%5D = -1;%0A        %7D%0A    %7D%0A%0A    private void swim(int k) %7B%0A        while (k %3E 1 && greater(k / 2, k)) %7B%0A            exch(k / 2, k);%0A            k = k / 2;%0A        %7D%0A    %7D%0A%0A    private void sink(int k) %7B%0A        while (2 * k %3C= len) %7B%0A            int j = 2 * k;%0A            if (j %3C len && greater(j, j + 1)) %7B%0A                j++;%0A            %7D%0A            if (!greater(k, j)) %7B%0A                break;%0A            %7D%0A            exch(k, j);%0A            k = j;%0A        %7D%0A    %7D%0A%0A    private boolean greater(int source, int target) %7B%0A        return keys%5Bpq%5Bsource%5D%5D.compareTo(keys%5Bpq%5Btarget%5D%5D) %3E 0;%0A    %7D%0A%0A    private void exch(int source, int target) %7B%0A        int tmp = pq%5Bsource%5D;%0A        pq%5Bsource%5D = pq%5Btarget%5D;%0A        pq%5Btarget%5D = tmp;%0A        qp%5Bpq%5Bsource%5D%5D = source;%0A        qp%5Bpq%5Btarget%5D%5D = target;%0A    %7D%0A%0A    @Override%0A    public Iterator iterator() %7B%0A        return null;%0A    %7D%0A
 %0A%7D%0A

update the indexMaxPQ