如何将冒泡排序部分算法抽象成函数
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Edit1: TEdit;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
function paixu(var n:Integer):String;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
num:Array of Integer;
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Str:String;
i,j:Integer;
temp:String;
begin
Str:=Trim( Edit1.Text );
SetLength(num,Length(Str));
i:=1;
j:=1;
While ( i<=Length(Str) ) do
begin
While ((Str<>#32)And(Str<>#0)) do
begin
temp:=temp+Str;
i:=i+1;
end;
num:=StrToInt(temp);
j:=j+1;
i:=i+1;
temp:='';
Edit1.Text:=paixu(i-1);//系统提示此处有问题 Types of actual and formal var parameters must be idential
end;
end;
function TForm1.paixu(var n:Integer):String;
var
temp:Integer;
m,k,j:Integer;
begin
For m:=1 to n-1 do
begin
k:=n-m;
For j:=1 to k do
begin
If (num>num) then
begin
temp:=num;
num:=num;
num:=temp;
end;
end;
end;
Edit1.Text:='';
For j:=1 to n do
Result:=Edit1.Text+' '+IntToStr(num);
end;
end. 我也是刚学
76 jieguo:=jieguo+.‘ ’ inttostr(num)
end;
result:= jieguo
74 去掉
传址那里传j的过去 51哪里写在循环外
edit1.text:=paixu(j);
页:
[1]