In this Delphi code, should be store the minmum value into newA and delete it from A , this repeated until A reached to the size 0
type TDoubleDynArray = array of Double;
..............
..........
//Get minimum value:
function MinValue(var minPos : Integer; Data: TDoubleDynArray): Double;
var
I: Integer;
begin
ShowMessageUser(IntToStr( Length(data)));
Result := Data[Low(Data)];
for I := Low(Data) + 1 to High(Data) do
if Result > Data[I] then
minPos := i;
Result := Data[minPos];
end;
//-------------------------Main function ------------------
function TForm1.Func(X: TDoubleDynArray): Double;
var
A, newA : TDoubleDynArray;
i, minPos : Integer;
begin
SetLength(A, 55);
SetLength(newA, 55);
A := Copy(X,0, 55);
for i := 0 to 54 do
begin
newA[i] := MinValue(MinPos,A);
Delete(A, MinPos, 1);
end;
..............
..........
end;
When i run the code it stop on size 3 (length of A = 3):
The Result of function MinValue() //ShowMessageUser(IntToStr( Length(data)));
55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 3 3
What I should change to get the right result (length(A) := 0)???