标题:一个新手的问题(大家不要笑我)
只看楼主
wyp1984
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-3-18
 问题点数:0 回复次数:0 
一个新手的问题(大家不要笑我)

我才接触DELPHI,所以有个小问题想请教各位前辈.
题目:用冒泡法对输入的一组数排序(小到大)
我会写代码但我不知道该如何加在DELPHI的源代码里,搞了半天也不对,希望各位前辈能指点我一下,谢谢
源代码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type queue = array[1..10] of integer;

TForm1 = class(TForm)
Labts: TLabel;
labresult: TLabel;
dataedit: TEdit;
datalist: TListBox;
input: TButton;
sort: TButton;
close: TButton;

procedure sort1(var queue1:queue;n:integer);
procedure swap(x,y:integer);
procedure inputClick(Sender: TObject);
procedure sortClick(Sender: TObject);
private
{ Private declarations }

public
{ Public declarations }
end;

var
Form1: TForm1;
i:integer;
dataarray:queue;
implementation
procedure sort1(var queue1:queue;n:integer);
var k,j:integer;
flag:boolean;
begin
for k:=1 to n-1 do
begin
flag:= true;
for j:=1 to n-k do
if queue1[j]<queue1[j-1] then
begin
flag:=false;
swap(queue1[j],queue1[j+1]);
end;
if flag then
exit;
end;
end;
procedure swap (var x,y:integer);
var temp:integer;
begin
temp:=x;
x:=y;
y:=temp;
end;

{$R *.dfm}

procedure TForm1.inputClick(Sender: TObject);
begin
i:=i+1;
dataarray[i]:=strtoint(dataedit.Text);
datalist.Items.Add(dataedit.Text);
dataedit.Text'';
dataedit.SetFocus;
end;

procedure TForm1.sortClick(Sender: TObject);
var j:integer;
begin
labresult.caption :='这组数从小到大排列为:'+chr(13);
sort1(dataarray,i);
for j:=1 to i do
labresult.caption:=labresult.caption+''+inttostr(dataarray[j]);
i:=0
end;

end.

搜索更多相关主题的帖子: interface Windows 源代码 如何 
2006-03-19 00:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-51290-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.689679 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved