unit
Unit1;
interface
uses
Winapi
.
Windows, Winapi
.
Messages, System
.
SysUtils, System
.
Variants, System
.
Classes, Vcl
.
Graphics,
Vcl
.
Controls, Vcl
.
Forms, Vcl
.
Dialogs, Vcl
.
Grids, Vcl
.
StdCtrls;
type
TForm1 =
class
(TForm)
Button1: TButton;
Button2: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button3: TButton;
StringGrid3: TStringGrid;
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
procedure
Button3Click(Sender: TObject);
private
public
end
;
const
cou =
5
;
var
Form1: TForm1;
table:
array
[
1..
cou,
1..
cou]
of
integer
;
implementation
{$R *.dfm}
procedure
TForm1
.
Button1Click(Sender: TObject);
begin
var
i,j:
integer
;
begin
randomize;
for
i :=
1
to
cou
do
for
j :=
1
to
cou
do
begin
table[i,j]:=random(
100
);
end
;
with
stringgrid1
do
begin
colcount:= cou +
1
;
rowcount := cou +
1
;
for
i :=
1
to
cou
do
for
j :=
1
to
cou
do
begin
Cells[i,j] := inttostr(table[i,j]);
end
;
end
;
end
;
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
var
i,j,p,b,a:
integer
;
begin
for
a :=
1
to
cou
do
begin
for
p :=
1
to
cou
do
for
i:=
1
to
cou
do
for
j:=
1
to
cou-
1
do
if
table[i,j] > table[i,j+
1
]
then
begin
b:=table[i,j];
table[i,j]:=table[i,j+
1
];
table[i,j+
1
]:=b;
end
;
for
p :=
1
to
cou
do
for
i:=
1
to
cou-
1
do
for
j:=
1
to
cou
do
if
table[i,j] > table[i+
1
,j]
then
begin
b:=table[i,j];
table[i,j]:=table[i+
1
,j];
table[i+
1
,j]:=b;
end
;
end
;
with
stringgrid2
do
begin
colcount:= cou +
1
;
rowcount := cou +
1
;
for
i :=
1
to
cou
do
for
j :=
1
to
cou
do
begin
cells[i,j]:= inttostr(table[i,j]);
end
;
end
;
end
;
procedure
TForm1
.
Button3Click(Sender: TObject);
var
i,j:
integer
;
begin
for
i :=
1
to
cou
do
for
j :=
1
to
cou
do
if
( j>=i )
then
table[i,j]:=
0
;
with
stringgrid3
do
begin
colcount:= cou +
1
;
rowcount := cou +
1
;
for
i :=
1
to
cou
do
for
j :=
1
to
cou
do
begin
cells[i,j]:= inttostr(table[i,j]);
end
;
end
;
end
;
end
.