[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Infinite loop" error - Need EasyLanguage Expert.



PureBytes Links

Trading Reference Links

Here's a faster sort routine which Alex Matulich posted to the list a
while back.

-- 
  Dennis

------------------------------------------------------------------------

{Function: _heapsort_a
 by Alex Matulich
 Adapted from _Numerical Recipes in C_

 This function sorts an array ra[] from index 0 to N.

 Lines marked with [*] are fixed from previous version, to
 work correctly on EasyLanguage arrays which have a lowest
 index of 0, instead of 1.
 }

inputs:
    ra[m](NumericArrayRef),   {array to be sorted}
    N(NumericSimple);         {highest array index}

vars: NN(0), ii(0), ir(0), jj(0), ll(0), rra(0), lp1(true), lp2(true);
if m < N then NN = m else NN = N;
if NN > 0 then begin         {*}
    ll = IntPortion(0.5*NN); {*}
    ir = NN;
    while lp1 begin
        if ll > 0 then begin {*}
            ll = ll-1;
            rra = ra[ll];
        end else begin
            rra = ra[ir];
            ra[ir] = ra[0];
            ir = ir-1;
            if ir = 0 then begin
                ra[0] = rra;
                lp1 = false;
            end;
        end;
        ii = ll;
        jj = ll+ll;
        lp2 = true;
        while lp1 and lp2 and jj <= ir begin
            if jj < ir and ra[jj] < ra[jj+1] then jj = jj+1;
            if rra < ra[jj] then begin
                ra[ii] = ra[jj];
                ii = jj;
                jj = jj+jj;
            end else lp2 = false;
        end;
        ra[ii] = rra;
    end;
end;
_heapsort_a = NN; {dummy return value}