Показать сообщение отдельно
  #4  
Старый 12.05.2010, 20:27
skaynet45 skaynet45 вне форума
Прохожий
 
Регистрация: 12.05.2010
Сообщения: 4
Репутация: 10
По умолчанию

Вообщем решил сделать одномерный, получилось но есть недочёты:
во первых бывает выводит 2 одинаковых числа незнаю как сделать чтоб они отсеивались
во вторых сортирует правильно после 3-5 нажатий на кнопку
Вот код
Код:
var
  Form1: TForm1;
  x: array[1..10] of integer;

implementation

{$R *.dfm}




procedure TForm1.Button4Click(Sender: TObject);
var  i: integer;
begin
randomize;
for i:=1 to 10 do
x[1]:=random(100)+1;
x[2]:=random(100)+1;
x[3]:=random(100)+1;
x[4]:=random(100)+1;
x[5]:=random(100)+1;
x[6]:=random(100)+1;
x[7]:=random(100)+1;
x[8]:=random(100)+1;
x[9]:=random(100)+1;
x[10]:=random(100)+1;
Form1.Edit1.Text:=inttostr(x[1]);
Form1.Edit2.Text:=inttostr(x[2]);
Form1.Edit3.Text:=inttostr(x[3]);
Form1.Edit4.Text:=inttostr(x[4]);
Form1.Edit5.Text:=inttostr(x[5]);
Form1.Edit6.Text:=inttostr(x[6]);
Form1.Edit7.Text:=inttostr(x[7]);
Form1.Edit8.Text:=inttostr(x[8]);
Form1.Edit9.Text:=inttostr(x[9]);
Form1.Edit10.Text:=inttostr(x[10]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var i,j,c,t,max: integer;
begin
for i:=10 downto 2 do
begin
max:=x[1];
c:=1;
begin
for j:=1 to i do
if x[i]> max then begin
                  max:=x[j];
                  c:=j;
                  end;
end;
t:=x[i];
x[i]:=x[c];
x[c]:=t;

end;
Form1.StringGrid1.Cells[0,0]:=inttostr(x[1]);
Form1.StringGrid1.Cells[1,0]:=inttostr(x[2]);
Form1.StringGrid1.Cells[2,0]:=inttostr(x[3]);
Form1.StringGrid1.Cells[3,0]:=inttostr(x[4]);
Form1.StringGrid1.Cells[4,0]:=inttostr(x[5]);
Form1.StringGrid1.Cells[5,0]:=inttostr(x[6]);
Form1.StringGrid1.Cells[6,0]:=inttostr(x[7]);
Form1.StringGrid1.Cells[7,0]:=inttostr(x[8]);
Form1.StringGrid1.Cells[8,0]:=inttostr(x[9]);
Form1.StringGrid1.Cells[9,0]:=inttostr(x[10]);
end;


procedure TForm1.Button2Click(Sender: TObject);
var i,j,c,t,min: integer;
begin
for i:=2 to 10 do
begin
min:=x[1];
c:=1;
begin
for j:=1 to i do
if x[i]< min then begin
                  min:=x[j];
                  c:=j;
                  end;
end;
t:=x[i];
x[i]:=x[c];
x[c]:=t;

end;
Form1.StringGrid1.Cells[0,0]:=inttostr(x[1]);
Form1.StringGrid1.Cells[1,0]:=inttostr(x[2]);
Form1.StringGrid1.Cells[2,0]:=inttostr(x[3]);
Form1.StringGrid1.Cells[3,0]:=inttostr(x[4]);
Form1.StringGrid1.Cells[4,0]:=inttostr(x[5]);
Form1.StringGrid1.Cells[5,0]:=inttostr(x[6]);
Form1.StringGrid1.Cells[6,0]:=inttostr(x[7]);
Form1.StringGrid1.Cells[7,0]:=inttostr(x[8]);
Form1.StringGrid1.Cells[8,0]:=inttostr(x[9]);
Form1.StringGrid1.Cells[9,0]:=inttostr(x[10]);
end;

end.
Подскажите плиз как решить эти недочёты?
Ответить с цитированием