unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
procedure Edit1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
numx: array of Integer; // 定义数组存放所输入的数字
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i, j, k,l, n : integer;
str, temp: String;
begin
str := Trim(Edit1.Text);
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;
// showmessage(temp);
i := i + 1;
numx := StrToInt(temp);
j := j+1;
temp := '';
end;
i := j; //以下的i,j与上述i,j意义不同。
for l := 1 to i - 1do //总共有i-1个实际有数字的数组变量
begin
k := i - l;//定义第k轮比较,递减式的,每次把最小值冒上去。i-L而不是i-1最少的循环。[效率高]
for j := 1 to k do
begin
if numx < numx then
begin
n := numx; //用中间值来互换两个数组值。
numx := numx;
numx := n;
end;
end;
end;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// for l := 1 to i - 1do//从大到小顺序,实际上是按数组下标从小到大。
edit1.Text :='';
for l := i - 1 downto 1 do // 从小到大顺序,实际上是按数组下标从大到小。
edit1.Text := edit1.Text + IntToStr(numx) + ' ';
end;
procedure TForm1.Edit1Click(Sender: TObject);
begin
Edit1.Text := '';
end;
end. while ((str<> #32) and (str<> #0)) do
begin
temp:=temp + str;
i:=i+1;
end;
//这里少了个 ‘i:=i+1;’
num:=StrToInt(temp);
j:=j+1;
temp:='';
end; {:5_103:}
:L
页:
[1]