![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
||||
|
||||
|
Имеется вот такая структура:
Код:
type
TStatusClient = (OffLine, OnLine, Away, Invisible);
TInvisStateClient = (clNormal, clInvisible, clVisible, clIgnore);
TContact=record
Nick,EMail:string;
status: TStatusClient;
invis: TInvisStateClient;
end;
var
Contacts:array of TContact;Сейчас использую вот такой алгоритм: Код:
var
stat:string;
i:integer;
t:TContact;
s1,s2:integer;
n1,n2:string;
begin
i:=0;
s1:=0;
s2:=0;
while i<Length(Contacts)-2 do begin
case Contacts[i].status of
OnLine:s1:=0;
Away:s1:=1;
Invisible:s1:=2;
OffLine:s1:=3;
end;
case Contacts[i+1].status of
OnLine:s2:=0;
Away:s2:=1;
Invisible:s2:=2;
OffLine:s2:=3;
end;
n1:=Contacts[i].Nick;
n2:=Contacts[i+1].Nick;
if(s1>s2)or((s1=s2)and(n1<n2))then begin
t:=Contacts[i];
Contacts[i]:=Contacts[i+1];
Contacts[i+1]:=t;
i:=0;
end else inc(i);
end;
end;Что посоветуете? |
|
#2
|
|||
|
|||
|
1. Использовать цикл For - минус одна проверка на итерацию.
2. Переписать механизм сравнения. у тебя он излишне сложный. Код:
For I := Low(Contacts) To High(Contacts)-1 Do
For J := I + 1 To High(Contacts) Do
Begin
If Contacts[i].Status = Contacts[J].Status
Then
Begin
If Contacts[i].Nick > Contacts[J].Nick Then
Begin
Buf := Contacts[i];
Contacts[i] := Contacts[J];
Contacts[J] := Buf;
End;
End
Else
If Contacts[i].Status > Contacts[J].Status Then
Begin
Buf := Contacts[i];
Contacts[i] := Contacts[J];
Contacts[J] := Buf;
End;
End; |
|
#3
|
||||
|
||||
|
Чуть переделал под себя - на 500 записей срабатывает почти мгновенно. Спасибо, тема закрыта.
|