|
发表于 2012-1-8 21:52:06
|
显示全部楼层
查错误挺费劲.我的事这样的
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 [1 .. 100] 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[i] <> #32) and (str[i] <> #0) do
begin
temp := temp + str[i];
i := i + 1;
end;
// showmessage(temp);
i := i + 1;
numx[j] := StrToInt(temp);
j := j+1;
temp := '';
end;
i := j; //以下的i,j与上述i,j意义不同。
for l := 1 to i - 1 do //总共有i-1个实际有数字的数组变量
begin
k := i - l;//定义第k轮比较,递减式的,每次把最小值冒上去。i-L而不是i-1最少的循环。[效率高]
for j := 1 to k do
begin
if numx[j] < numx[j+1] then
begin
n := numx[j]; //用中间值来互换两个数组值。
numx[j] := numx[j+1];
numx[j+1] := n;
end;
end;
end;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// for l := 1 to i - 1 do //从大到小顺序,实际上是按数组下标从小到大。
edit1.Text :='';
for l := i - 1 downto 1 do // 从小到大顺序,实际上是按数组下标从大到小。
edit1.Text := edit1.Text + IntToStr(numx[l]) + ' ';
end;
procedure TForm1.Edit1Click(Sender: TObject);
begin
Edit1.Text := '';
end;
end. |
|