(int n, double ra[])
| 30 | } |
| 31 | |
| 32 | public static void heapsort(int n, double ra[]) { |
| 33 | int l, j, ir, i; |
| 34 | double rra; |
| 35 | |
| 36 | l = (n >> 1) + 1; |
| 37 | ir = n; |
| 38 | for (;;) { |
| 39 | if (l > 1) { |
| 40 | rra = ra[--l]; |
| 41 | } else { |
| 42 | rra = ra[ir]; |
| 43 | ra[ir] = ra[1]; |
| 44 | if (--ir == 1) { |
| 45 | ra[1] = rra; |
| 46 | return; |
| 47 | } |
| 48 | } |
| 49 | i = l; |
| 50 | j = l << 1; |
| 51 | while (j <= ir) { |
| 52 | if (j < ir && ra[j] < ra[j+1]) { ++j; } |
| 53 | if (rra < ra[j]) { |
| 54 | ra[i] = ra[j]; |
| 55 | j += (i = j); |
| 56 | } else { |
| 57 | j = ir + 1; |
| 58 | } |
| 59 | } |
| 60 | ra[i] = rra; |
| 61 | } |
| 62 | } |
| 63 | } |