bubble sort
procedure Tform1 : bubule sort
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DB, ADODB, WinXP;
type
Tform1 =class(Tform)
Button1: TButton;
Button2: TButton;
StringGrid1: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Edit_nrp: TEdit;
Edit_nm: TEdit;
Label3: TLabel;
Edit_sks: TEdit;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
WinXP1: TWinXP;
procedure tbarang(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit_sksKeyPress(Sender: TObject; var Key: Char);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure swap(var angka1:string;var angka2:string);
public
{ Public declarations }
procedure SortGrid(Grid : TStringGrid; SortCol:integer);
end;
var
Form1: TForm1;
barisA,barisB,barisC :integer;
implementation
{$R *.dfm}
procedure Tform1.Sortgrid(Grid : TStringGrid; SortCol:integer);
var
i,j : integer;
temp:tstringlist;
begin
temp:=tstringlist.create;
with Grid do
for i := FixedRows to RowCount - 2 do {because last row has no next row}
for j:= i+1 to rowcount-1 do {from next row to end}
if AnsiCompareText(Cells[SortCol, i], Cells[SortCol,j]) > 0
then
begin
temp.assign(rows[j]);
rows[j].assign(rows[i]);
rows[i].assign(temp);
end;
temp.free;
end;
procedure Tform1.tbarang(sender:TObject);
begin
with StringGrid1 do
begin
ColCount :=5 ;
RowCount :=2;
FixedCols :=0;
DefaultRowHeight :=10;
Options :=[goFixedVertLine, goFixedHorzLine, goVertLine,goHorzLine,
goRangeSelect, goRowSelect];
Cells[0,0]:='nrp';
Cells[1,0]:='nama';
Cells[2,2]:='sks';
//lebarkolom
ColWidths[0]:=25;
ColWidths[1]:=50;
ColWidths[2]:=25;
end;
end;
procedure Tform1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='no';
StringGrid1.Cells[1,0]:='nrp';
StringGrid1.Cells[2,0]:='nama';
StringGrid1.Cells[3,0]:='sks';
end;
procedure Tform1.Button1Click(Sender: TObject);
var
i :Integer ;
no : array[1..100] of Integer ;
begin
if (Edit_nrp.Text =) or (Edit_nm.Text=) or (Edit_sks.Text=) then
ShowMessage('inputkan data dg lengkap terlebih dahulu')
else
begin
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.Cells[1,barisA+1]:=Edit_nrp.Text;
Inc(barisA);
Edit_nrp.Clear;
Edit_nrp.SetFocus;
StringGrid1.Cells[2,barisB+1]:=Edit_nm.Text;
Inc(barisB); Edit_nm.Clear;
StringGrid1.Cells[3,barisC+1]:=Edit_sks.Text;
Inc (barisC);Edit_sks.Clear;
end;
end;
procedure Tform1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
c,j:integer;
rect:trect;
begin
with stringgrid1 do
if y<rowheights[0] then {make sure row 0 was clicked}
begin
for j:= 0 to colcount-1 do {determine which column was clicked}
begin
rect := cellrect(j,0);
if (rect.Left < x) and (rect.Right> x) then
begin
c := j;
break;
end;
end;
sortgrid(stringgrid1,c);
end;
end;
procedure Tform1.Edit_sksKeyPress(Sender: TObject; var Key: Char);
begin
if (Edit_nrp.Text =) or (Edit_nm.Text=) or (Edit_sks.Text=) then
ShowMessage('inputkan data dg lengkap terlebih dahulu')
else
begin
if not(Key in['0'..'9',#13,#18])then key :=#0 ;
if key=#13 then
begin
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.Cells[1,barisA+1]:=Edit_nrp.Text;
Inc(barisA);
Edit_nrp.Clear;
Edit_nrp.SetFocus;
StringGrid1.Cells[2,barisB+1]:=Edit_nm.Text;
Inc(barisB); Edit_nm.Clear;
StringGrid1.Cells[3,barisC+1]:=Edit_sks.Text;
Inc (barisC);Edit_sks.Clear;
end;
end;
end;
procedure Tform1.Button2Click(Sender: TObject);
var
I,J,T :integer;
D :array [0..1000] of Integer ;
begin
end;
begin
end;
begin
end;
end.