偶也做了个 冒泡排序2.0 零基础做了6个小时,累啊
界面做的那个丑.哈!unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons;
type
TForm1 = class(TForm)
Edit1: TEdit;
BitBtn1: TBitBtn;
table1: TStringGrid;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button2: TButton;
Label5: TLabel;
Label6: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1; n:Integer; num:array of Integer;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
temp1,temp,str:string;
k,I,J:Integer;
begin
str:=trim(edit1.text); //trim 去除字符串两边的空格 LTRIM 去除左边空格 RTRIM 去除右边空格
k:=Length(str); //LENGTH 返回字符串长度 索引从1开始
label1.caption:='字符串长度='+INTTOSTR(K);
I:=1;
n:=1;
while I<=K do
begin
IF str<>#32 THEN //直接调用数组的方式 STR
begin
TEMP:=TEMP+STR;
temp1:=TEMP1+STR;
begin
if str=#32 then
num:=StrToInt(temp);
if i=k then
num:=StrToInt(temp);
end
end
ELSE
IF str=#32 THEN //查找下一个是不是空格,如果是空格继续查找 直到不是空格
begin
I:= I+0;
END
else
begin
num:=StrToInt(temp);
n:=n+1;
TEMP1:=TEMP1+' ';
TEMP:='';
end;
I:=I+1;
table1.Cells:=inttostr(NUM) ;
Label2.CAPTION:=temp1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:='';
label1.caption:='字符串长度=';
Label2.Caption:='零';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
table1.Visible:=false;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
l,j,k,m:Integer;
begin
for l:=1 to n-1 do
begin
k:=n-l;
for j:=1 to k do
begin
if num<num then
begin
m:=num ;
NUM:=num ;
NUM:=m;
end;
end;
end;
Label6.caption:='';
for l:=n downto 1 do
Label6.caption:=Label6.caption+' ' +inttostr(NUM)+' ';
end;
end.
{:1_1:}{:1_1:}{:1_1:}{:1_1:}看似不错~~~~~~~ 这还0基础?那我岂不,,, 参考什么写点啊
页:
[1]