procedure TForm1.Button1Click(Sender: TObject);
var
i,j,temp:integer;
a:array[0..7] of integer;
begin
for i:=0 to length(a)-1 do
begin
a[i]:=i;
end;
i:=0;
while(i<length(a)-1) do
begin
temp:=a[i];
a[i]:=a[i+1];
a[i+1]:=temp;
inc(i,2);
end;
end;
你看行不行啊?
把它在FORM1的画布上打出来,可以看的更清楚一些!
procedure TForm1.Button1Click(Sender: TObject);
var
data:array of integer;
i,Len:integer;
temp:integer;
begin
button1.Enabled:=false;
Len:=strtoint(inputbox('输入数字','请输入数组的长度',''));
setlength(data,len);
for i:=0 to len-1 do
begin
data[i]:=10+i;
form1.Canvas.TextOut(40,40+20*i,'data['+inttostr(i)+']: '+inttostr(data[i]));
end;
i:=0;
while i<len-1 do
begin
temp:=data[i];
data[i]:=data[i+1];
data[i+1]:=temp;
i:=i+2;
end;
for i:=0 to len-1 do
form1.Canvas.TextOut(150,40+20*i,'data['+inttostr(i)+']: '+inttostr(data[i]));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form1.Refresh;
button1.Enabled:=true;
end;