Amontoados

From Wiki**3

Revision as of 14:47, 19 May 2005 by Root (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implementação de Amontoado com Vector

Algoritmo fixUp

 void fixUp(Item a[], int k) {  /* sobe “k” */
   while (k > 1 && less(a[k/2], a[k])) {
     exch(a[k], a[k/2]);
     k = k/2;
   }
 }

Algoritmo fixDown

 void fixDown(Item a[], int k, int N) {  /* desce “k” */
   int j;
   while (2*k <= N) {
     j = 2*k;
     if (j < N && less(a[j], a[j+1])) j++;
     if (!less(a[k], a[j])) break;
     exch(a[k], a[j]); k = j;
   }
 }