1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Grids, unit3,Menus;
type
TForm1 = class(TForm)
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label4: TLabel;
Label5: TLabel;
Edit3: TEdit;
Label6: TLabel;
Edit4: TEdit;
Button1: TButton;
Grid1: TStringGrid;
MainMenu1: TMainMenu;
A1: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
Button3: TButton;
Label7: TLabel;
Grid2: TStringGrid;
Grid3: TStringGrid;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Button2: TButton;
Label1: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a : array of array of integer;
i,j,m,n,x,y : integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Caption := 'Main';
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
Edit8.Text:='';
randomize;
end;
procedure TForm1.Button1Click(Sender: TObject); //Генерация
begin
if (edit1.Text='') or (edit2.Text='') then
Application.MessageBox('Не введена размерность массива','Сообщение');
n:=strtoint(edit1.Text);
m:=strtoint(edit2.Text);
if (edit3.Text='') or (edit4.Text='') then
Application.MessageBox('Указанный диапазон не корректен','Сообщение');
x:=strtoint(edit3.Text);
y:=strtoint(edit4.Text);
setlength(a,n,m);
with Grid1 do
begin
ColCount:=m;
RowCount:=n;
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
a[i,j]:=random(x+y+1)-x;
Cells[j,i]:=inttostr(a[i,j]);
with Grid2 do
begin
ColCount:=m;
RowCount:=n;
end;
with Grid3 do
begin
ColCount:=m;
RowCount:=n;
end;
end;
end;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
form1.Close;
Form3.Show;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.N2Click(Sender: TObject); //Запись массива
var f: textfile;
begin
AssignFile(f,'Massiv.txt');
rewrite(f);
for i := 0 to n-1 do
begin
for j := 0 to m-1 do write (f,a[i,j]);
writeln(f);
end;
closefile(f);
end;
procedure TForm1.Button3Click(Sender: TObject); //Вставка
var
key,k:integer;
begin
with Grid1 do
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
a[i,j]:=StrToInt(Cells[i,j]);
end;
if (StrToInt(Edit5.Text)<StrToInt(Edit7.Text)) or (StrToInt(Edit6.Text)<StrToInt(Edit8.Text)) then
if ((StrToInt(Edit5.Text)<(StrToInt(Edit1.Text))) or (StrToInt(Edit6.Text)<(StrToInt(Edit2.Text)))) then
begin
for i:=StrToInt(Edit5.Text) to StrToInt(Edit7.Text) do
for j:=StrToInt(Edit6.Text) to StrToInt(Edit8.Text) do
begin
key:=a[i][j];
k:=i-1;
while ((k>=0) and (a[k][j]>key)) do begin
a[k+1][j]:=a[k][j];
k:=k-1;
end;
a[k+1][j]:=key;
end;
with Grid2 do
begin
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
Cells[j,i]:=inttostr(a[j,i]);
end;
end;
end else Application.MessageBox('Диапазон для сортировки выбран неверно!','Ошибка')
else Application.MessageBox('Диапазон для сортировки выбран неверно!','Ошибка');
end; |