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

Re: 2D & 3D array sort functions?



PureBytes Links

Trading Reference Links

At 6:09 AM -0700 7/13/00, Larry Wright wrote:

>Would anyone have functions for sorting 2 & 3-dimension arrays in TS?
>Arrays will be small (<40 in the sort dimension), will be 'almost sorted',
>and new data inserted 1 record at a time. Since they will be sorted many
>times, the fastest techniques for sorting such arrays would be most
>appreciated, but any method will do for now :-).

Attached is EasyLanguage code for a very fast sort routine. This code is an
indicator that test the sort code so you should be able to extract the code
that actually does the sort.

I use it all the time. (I think I got the algorithm from Bob Brickey of
Scientific Approaches but I have forgotten.)

Bob Fulks



Input:    Max(100);
Vars:     K(0), J(0);
Array:    Arr[100](0);

if Date > 970901 then Print("1  ", Date:6:0, CurrentBar:5:0, K:3:0,
   Arr[K]:5:2);

if Date = 970908 then begin
  for K = 1 to Max begin
     Arr[K] = Close[K];
     Print("2  ", Date:6:0, CurrentBar:5:0, K:3:0, Arr[K]:5:2);
  end;
  K = 0;
end;

if LastBarOnChart then begin

  for K = 1 to Max - 1 begin
     for J = K + 1 to Max begin
       if Arr[J] < Arr[K] then begin
          Value1 = Arr[K];
          Arr[K] = Arr[J];
          Arr[J] = Value1;
          Print(K:3:0, J:3:0, Arr[K]:5:2, Arr[J]:5:2);
       end;
     end;
  end;

  for K = 1 to Max begin
     Print("3  ", Date:6:0, CurrentBar:5:0, K:3:0, Arr[K]:5:2);
  end;

end;

Plot1(0,"Plot1");