Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.05.02;
Скачать: CL | DM;

Вниз

Как отсортировать список?   Найти похожие ветки 

 
siriusP   (2004-04-14 12:34) [0]

Подскажите алгоритм как отсортировать список, в котором лежит структура TRec.
Нужно, чтобы елементы шли по порядку
[0,0][1,0][0,1][1,1][0,2][1,2]...:
type
 TRec = class
   aCol: integer;
   aRow: integer;
   ...
 end;

 TMyClass = class
   FRec: TList;
   ...
   Sort();
 end;
...

Такая ф-ия неверная, в ней явно не хватает:
function CompareRec(Item1, Item2: Pointer): Integer;
begin
 result:= CompareValue(TRec(Item1).aCol, TRec(Item2).aCol);
end;

procedure TMyClass.Sort();
begin
 FRec.Sort(@CompareRec);
end;

Прошу помочь. Спасибо.


 
Семен Сорокин ©   (2004-04-14 12:38) [1]

type
 PRec = ^TRec;

function CompareRec(Item1, Item2: Pointer): Integer;
begin
result:= CompareValue(PRec(Item1)^.aCol, PRec(Item2)^.aCol);
end;


 
Семен Сорокин ©   (2004-04-14 12:41) [2]

сорри,
вот так:
function CompareRec(Item1, Item2: Pointer): Integer;
begin
Result := CompareValue(PRec(Item1)^.aCol, PRec(Item2)^.aCol);
if Result = 0 then
 Result := CompareValue(PRec(Item1)^.aRow, PRec(Item2)^.aRow)
end;


 
Курдль ©   (2004-04-14 12:43) [3]


function CompareRec(Item1, Item2: Pointer): Integer;
begin
result:= CompareValue(TRec(Item1).aCol, TRec(Item2).aCol);
end;

function CompareRec(Item1, Item2: Pointer): Integer;
var ItPtr1, ItPtr2: ^TRec;
begin
 ItPtr1 := Item1;
 ItPtr2 := Item2;
 if ItPtr1.Col > ItPtr2.Col then Result := 1                      
   else
     if ItPtr1.Col = ItPtr2.Col then
     begin
       if ItPtr1.Row > ItPtr2.Row then Result := 1
         else
           if ItPtr1.Row = ItPtr2.Row then Result := 0
              else Result := -1;
                 
     end else Result := -1;
end;

procedure TMyClass.Sort();
begin
FRec.Sort(CompareRec);
end;



 
siriusP   (2004-04-14 14:17) [4]

Премного благодарен.



Страницы: 1 вся ветка

Текущий архив: 2004.05.02;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.046 c
1-1081855137
infom
2004-04-13 15:18
2004.05.02
dxStatusBar


3-1080901697
Skulll
2004-04-02 14:28
2004.05.02
Веб клиент на PHP, ASP, JSP или CGI


9-1069828528
Eagle Owl
2003-11-26 09:35
2004.05.02
Конвертирование 3ds-файлов в x-файлы...


6-1079087976
Dimmm
2004-03-12 13:39
2004.05.02
управление удаленным компьютером по локальной сети


14-1081770518
kaif
2004-04-12 15:48
2004.05.02
Контент-фильтрация SpamAssassin