鱼C论坛

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

如何将冒泡排序部分算法抽象成函数

[复制链接]
发表于 2017-12-23 14:10:10 | 显示全部楼层 |阅读模式

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

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

x
  1. unit Unit1;

  2. interface

  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, Buttons;

  6. type
  7.   TForm1 = class(TForm)
  8.     Edit1: TEdit;
  9.     BitBtn1: TBitBtn;
  10.     procedure BitBtn1Click(Sender: TObject);
  11.     function paixu(var n:Integer):String;
  12.   private
  13.     { Private declarations }
  14.   public
  15.     { Public declarations }
  16.   end;

  17. var
  18.   Form1: TForm1;

  19. implementation
  20. var
  21. num:Array of Integer;

  22. {$R *.dfm}

  23. procedure TForm1.BitBtn1Click(Sender: TObject);
  24. var
  25. Str:String;
  26. i,j:Integer;
  27. temp:String;
  28. begin
  29. Str:=Trim( Edit1.Text );
  30. SetLength(num,Length(Str));
  31. i:=1;
  32. j:=1;
  33. While ( i<=Length(Str) ) do
  34. begin
  35.   While ((Str[i]<>#32)And(Str[i]<>#0)) do
  36.   begin
  37.    temp:=temp+Str[i];
  38.    i:=i+1;
  39.   end;
  40.   num[j]:=StrToInt(temp);
  41.   j:=j+1;
  42.   i:=i+1;
  43.   temp:='';
  44.   Edit1.Text:=paixu(i-1);  //系统提示此处有问题 Types of actual and formal var parameters must be idential
  45. end;
  46. end;


  47. function TForm1.paixu(var n:Integer):String;
  48. var
  49. temp:Integer;
  50. m,k,j:Integer;
  51. begin
  52.   For m:=1 to n-1 do
  53. begin
  54.   k:=n-m;
  55.   For j:=1 to k do
  56.   begin
  57.    If (num[j]>num[j+1]) then
  58.    begin
  59.    temp:=num[j];
  60.    num[j]:=num[j+1];
  61.    num[j+1]:=temp;
  62.    end;
  63.   end;
  64. end;
  65. Edit1.Text:='';
  66. For j:=1 to n do
  67. Result:=Edit1.Text+' '+IntToStr(num[j]);
  68. end;


  69. end.
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-27 00:00:23 From FishC Mobile | 显示全部楼层
我也是刚学
76 jieguo:=jieguo+.‘ ’
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-27 00:09:58 From FishC Mobile | 显示全部楼层
inttostr(num[j])
end;
result:= jieguo
74 去掉
传址那里传j的过去
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-27 00:15:17 From FishC Mobile | 显示全部楼层
51哪里写在循环外
edit1.text:=paixu(j);
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-28 23:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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