И посмотрите что я не так начала делать, я немного начала и уже не получается!
Задание:
1.Установить на форму:
-2 табл. StringGrid (1- для ввода массива, 2 - для вывода отсортированого массива)
-задать значение true в св-ва Options->GoEditing
-2 кнопки Button (начало сортировки массива и закрытия приложения)
-3 индикатора ChekBox (для выбора метода сотрировки "обмен", "выбор", "Вставка")
2. Описать переменную mas (двумерный массив (a*b)) и т.д
3.НАписать процедуру по нажатию на кнопку 1;
-заполнения переменной mas числами из табл.1
- по выбору соответ. индикатора отсортировать данный массив заданным методом
-вывести отсоритрованый массив в табл.2
Само задание!
Отсортировать массив по убыванию элементов чётных столбцов!
Код
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const a=4; b=4;
var
Form1: TForm1;
mas array [1..a, 1..b] of integer;
var i,j,k:byte;
x:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
for i:=1 to a do
for j:=1 to b do
mas [i,j]:=strtoint(stringgrid1.Cells);
if chekbox1.checked then
for j:=1 to b do
for k:=a downto 2 do
for i:=1 to k-1 do
if mas [i,j]>mas[i+1,j] then
begin
x:=mas[i,j];
mas[i,j]:=mas[i+1,j];
mas[i+1,j]:=x
end;
for i:=1 to a do
for j:=1 to b do
stringgrid2.Cells[j,i]:=inttostr(mas(i,j));
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const a=4; b=4;
var
Form1: TForm1;
mas array [1..a, 1..b] of integer;
var i,j,k:byte;
x:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
for i:=1 to a do
for j:=1 to b do
mas [i,j]:=strtoint(stringgrid1.Cells);
if chekbox1.checked then
for j:=1 to b do
for k:=a downto 2 do
for i:=1 to k-1 do
if mas [i,j]>mas[i+1,j] then
begin
x:=mas[i,j];
mas[i,j]:=mas[i+1,j];
mas[i+1,j]:=x
end;
for i:=1 to a do
for j:=1 to b do
stringgrid2.Cells[j,i]:=inttostr(mas(i,j));
end;
end.