이거 에러좀 수정해줘요...
잉...초보라서 디버깅도 잘못하겠어용...
수의 범위를 입력받아서 정렬하는 프로그램...
소스------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
edtInput: TEdit;
btnRand: TButton;
btnUpsort: TButton;
btnDnsort: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure Draw;
procedure btnRandClick(Sender: TObject);
procedure btnUpsortClick(Sender: TObject);
procedure btnDnsortClick(Sender: TObject);
private
{ Private declarations }
public
function sort(flag:integer):boolean;
{ Public declarations }
end;
var
Form1: TForm1;
Rand:array[0..4] of integer;
implementation
{$R *.DFM}
procedure TForm1.Draw;
var
i:integer;
begin
ListBox2.Items.clear;
for i:=0 to 4 do begin
ListBox2.Items.Add(inttostr(Rand[i]));
end;
end;
function TForm1.sort(flag:integer):boolean;
var
i,j,tmp:integer;
begin
tmp:=0;
case flag of
1:begin
for i:=0 to 4 do
for j:=0 to 4 do begin
if rand[j]>rand[i] then begin
tmp:=rand[j];
rand[j]:=rand[i];
rand[i]:=tmp;
end;
end;
result:=true;
end;
2:begin
for i:=0 to 4 do
for j:=0 to 4 do begin
if rand[i]>rand[j] then begin
tmp:=rand[i];
rand[i]:=rand[j];
rand[j]:=tmp;
end;
end;
result:=true;
end;
end;
end;
procedure TForm1.btnRandClick(Sender: TObject);
var
i,j:integer;
begin
j:=strToint(edtInput.text);
randomize;
Listbox1.Items.clear;
for i:=0 to 4 do begin
rand[i]:=random(j);
ListBox1.Items.Add(intTOstr(rand[i]));
end;
end;
procedure TForm1.btnUpsortClick(Sender: TObject);
var
R:boolean;
begin
R:sort(1);
if R then
Draw
else
showmessage('정렬실패');
end;
procedure TForm1.btnDnsortClick(Sender: TObject);
var
R:boolean;
begin
R:=sort(2);
if R then
Draw
else
showmessage('정렬 실패');
end;
end.
답변해놨어요~