wykonując taki kod:
procedure Sort(const ASize: Integer; AIn: array of Integer; var AOut: Array of Integer);
var
I, J, K, Found: Integer;
begin
for I:=0 to ASize do
AOut[I]:=-1;
AOut[0]:=AIn[0];
for I:=1 to ASize do
begin
Found:=AIn[I];
for J:=0 to ASize do
begin
if AOut[J]>Found then
begin
for K:=ASize downto J-1 do
begin
if K-1>=0 then
AOut[K]:=AOut[K-1]
end;
AOut[J]:=Found;
Break;
end
else
if AOut[J]=-1 then
AOut[J]:=Found;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Size, I: Integer;
Unsorted, Sorted: array of Integer;
Contains: string;
begin
Randomize;
Size:=StrToInt(Edit1.Text);
SetLength(Unsorted, Size);
SetLength(Sorted, Size);
Memo1.Lines.Add('Log: Begin');
for I:=0 to Size do
begin
Unsorted[I]:=Random(255);
Contains:=Contains+IntToStr(Unsorted[I])+', ';
end;
Memo1.Lines.Add(Contains);
Memo1.Lines.Add('Log: Begin sort');
Contains:='';
Sort(Size, Unsorted, Sorted);
Memo1.Lines.Add('Log: End sort');
for I:=0 to Size do
begin
Contains:=Contains+IntToStr(Sorted[I])+', ';
end;
Memo1.Lines.Add(Contains);
Memo1.Lines.Add('Log: End');
end;
Dostaje informacje o "Invalid pointer operation". Kod już sprawdzam trzeci dzień i nic nie mogę wykombinować, aby to poprawić.
ps. to jest algorytm na sortowanie przez wstawianie...