
19.03.2010, 16:13
|
Прохожий
|
|
Регистрация: 14.03.2010
Сообщения: 14
Репутация: 10
|
|
Помогите с комментариями!
Я не прошу писать комментарии к каждой строчке, просто хотя бы в общем...
условие:
В произвольном массиве поменяйте местами соседние четные и нечетные по номеру элементы. Дополнительные массивы не использовать.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
temp,temp1:string;
begin
if(StringGrid1.ColCount mod 2 = 1) then
temp1 := StringGrid1.Cells[StringGrid1.colcount-1,0];
for i := 0 to stringgrid1.ColCount div 2 do begin
temp := stringgrid1.Cells[2*i,0];
StringGrid1.Cells[2*i,0]:= StringGrid1.Cells[2*i+1,0];
StringGrid1.Cells[2*i+1,0] := temp;
end;
if(StringGrid1.ColCount mod 2 = 1) then
StringGrid1.Cells[StringGrid1.colcount-1,0] := temp1;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
randomize;
for i:= 0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[i,0] := inttostr(random(128));
end;
end.
|