鱼C论坛

 找回密码
 立即注册
查看: 3003|回复: 3

[原创] 偶也做了个 冒泡排序2.0 零基础做了6个小时,累啊

[复制链接]
发表于 2012-7-28 23:28:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
界面做的那个丑.哈!

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[1..100] 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[I]<>#32 THEN       //直接调用数组的方式 STR[I]
        begin
          TEMP:=TEMP+STR[I];
          temp1:=TEMP1+STR[I];
            begin
             if str[i+1]=#32 then
               num[n]:=StrToInt(temp);
             if i=k then
               num[n]:=StrToInt(temp);
             end
        end
     ELSE
       IF str[I+1]=#32 THEN    //查找下一个是不是空格,如果是空格继续查找 直到不是空格
        begin
          I:= I+0;
        END
       else
        begin
         num[n]:=StrToInt(temp);
         n:=n+1;
         TEMP1:=TEMP1+' ';
         TEMP:='';
        end;
     I:=I+1;
     table1.Cells[0,n-1]:=inttostr(NUM[n]) ;
     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[j]<num[j+1] then
            begin
              m:=num[j]       ;
              NUM[j]:=num[j+1] ;
              NUM[j+1]:=m;
            end;
        end;
    end;
    Label6.caption:='';
    for l:=n downto 1 do
    Label6.caption:=Label6.caption+' ' +inttostr(NUM[l])+' ';
end;
end.

冒泡排序2.0-20120728.rar

191.64 KB, 下载次数: 16

冒泡

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-7-29 09:53:53 | 显示全部楼层
{:1_1:}{:1_1:}{:1_1:}{:1_1:}看似不错~~~~~~~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2019-3-10 13:12:23 | 显示全部楼层
这还0基础?那我岂不,,,
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-10 13:12:57 | 显示全部楼层
参考什么写点啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 06:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表