Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 16.06.2009, 04:40   #1
01010101irk
Новичок
Джуниор
 
Аватар для 01010101irk
 
Регистрация: 16.06.2009
Сообщений: 1
По умолчанию Сортировка матрицы змейкой (Delphi)

Огромная помочь сделать, а даже точнее сделать (т.к. я в этом нуб) эту сортировку условие есть исходник с автозаполнением стрингрида http://upwap.ru/454509
есть похожая сортирока только из нижнего левого угла и чуть чуть корявая
Код:
Procedure TForm1.Button5Click(Sender: TObject);
 var
  i,j,k,c,p,l:integer;
  a:array of integer;
  t:string;
  b:boolean;
 begin
  k:=0;
   SetLength(a,StringGrid1.ColCount*StringGrid1.ColCount);
    For i:=0 to  StringGrid1.ColCount-1 do
    For j:=0 to  StringGrid1.RowCount-1 do
  begin
    a[k]:=StrToInt(StringGrid1.Cells[j,i]);
     k:=k+1;
  end;

 for i:=0 to (StringGrid1.ColCount*StringGrid1.RowCount)-1 do
   for k:=i+1 to (StringGrid1.ColCount*StringGrid1.RowCount)-1 do
    if a[k]<a[i] then
  begin
   c:=a[k];
   a[k]:=a[i];
   a[i]:=c;
 end;
  i:=0;
  t:=Edit1.Text;
  l:=StrToInt(t)-1;
   j:=l;
 StringGrid2.Cells[i,StringGrid1.RowCount-1]:=IntToStr(a[0]);
 k:=0;
repeat
 p:=p+1;

  if (j=l) and (i=0) then
  begin
    i:=i+1;
     end;

  if (j=l) then
  begin
   b:=false;
  end;
  if (i=0) then
  begin
   b:=true;
  end;
  
 if (b=false) and (j=l) then
     begin
    k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
  repeat
     k:=k+1;
     i:=i-1;
     j:=j-1;
   StringGrid2.Cells[i,j]:=IntToStr(a[k]);
   until i=0;
   b:=true;
   if j=0 then
   i:=i+1
   else
   j:=j-1;
     end;

   if (b=true)  and (j=l-1) then
   begin
   k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
    i:=i+110;
    j:=j+110;
   end;

    if (b=true)  and (i=l) and (j=0) then
   begin
   k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
    i:=i+110;
    j:=j+110;
   end;
   
   if (b=false) and (j<l) then
     begin
    k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
  repeat
     k:=k+1;
     i:=i-1;
     j:=j-1;
   StringGrid2.Cells[i,j]:=IntToStr(a[k]);
   until j=0;
   b:=true;
   if j=0 then
   begin
    i:=i+1;
   end
   else
  j:=j-1;
     end;

 if (b=true) and (i=0) then
     begin
    k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
  repeat
     k:=k+1;
     i:=i+1;
     j:=j+1;
   StringGrid2.Cells[i,j]:=IntToStr(a[k]);
   until j=l;
   b:=false;
   if i=l then
   j:=j-1
   else
   i:=i+1;
     end;

   if (b=true) and (j=0) and (i<>l) then
     begin
    k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
  repeat
     k:=k+1;
     i:=i+1;
     j:=j+1;
   StringGrid2.Cells[i,j]:=IntToStr(a[k]);
   until i=l;
   if i=l then
   j:=j-1;
     end;

     if (b=true) and (i=l) and (j>0) then
     begin
        k:=k+1;
    StringGrid2.Cells[i,j]:=IntToStr(a[k]);
     repeat
     k:=k+1;
     i:=i-1;
     j:=j-1;
   StringGrid2.Cells[i,j]:=IntToStr(a[k]);
   until j=0;
   if j=0 then
   i:=i+1;
     end;
 until p=(StringGrid1.ColCount-1)*(StringGrid1.RowCount-1);
 end;
end.
01010101irk вне форума Ответить с цитированием
Старый 16.06.2009, 10:29   #2
fbus
Форумчанин
 
Аватар для fbus
 
Регистрация: 23.10.2008
Сообщений: 460
По умолчанию

стучите в аську, обсудим
fbus вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Сортировка матрицы Dartchuwak Помощь студентам 4 06.04.2010 15:49
Матрицы. Сортировка Ominous48 Паскаль, Turbo Pascal, PascalABC.NET 5 18.05.2009 11:51
Вывод символов в StringGrid спиралью и змейкой (Delphi) ekzobyte Помощь студентам 1 02.04.2009 19:34