堆排序:了解Skiena的泡沫破灭实施

时间:2015-05-04 12:23:52

标签: java algorithm

需要帮助来了解bubble_down实施的一部分:

bubble down(priority queue q, int p)
    {
        int c; (* child index *)
        int i; (* counter *)
        int min index; (* index of lightest child *)
        c = pq_young_child(p); 
        min index = p;
        for (i=0; i<=1; i++)
            if ((c+i) <= q->n) {
                if (q->q[min index] > q->q[c+i]) min index = c+i; }
        if(min index!=p){
            pq swap(q,p,min index); bubble down(q, min index); }
        }
}

pq_young_child(p)的用途以及for loop如何有用?

0 个答案:

没有答案
相关问题