witam mogl by mi ktos poprawic kod do sortowania babelkowego .
chodzi mi o to zeby po nacisniciu button2 posortowalo stringgrida.
mam takie zadanie(4. Sortowanie tablicy jednowymiarowej o elementach typu Double metodą "bąbelkową".stringGrid)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i, j,n,x, k: integer;
koniec:boolean;
begin
StringGrid1.RowCount:=StrToInt(Edit1.Text);
for j:=0 to StringGrid1.RowCount-1 do
begin
k:= Random(30);
if (k mod 2 < 1) then
begin
StringGrid1.cells[i,j]:=IntToStr(k);
end
else
if (k mod 2 <> 0) then
begin
StringGrid1.cells[i,j]:=IntToStr(k);
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i, j, LiczbaPol, Temp : Integer;
begin
LiczbaPol :=StrToInt(Edit1.Text);
for j := 0 to LiczbaPol - 2 do
begin
for
i := 0 to LiczbaPol - 2 do
begin
if StringGrid1[i] >tabela[i+1] then
begin
Temp := tabela[i];
Stabela[i] := tabela[i+1];
tabela[i+1] := Temp;
end;
end;
end.