16,749
社区成员
发帖
与我相关
我的任务
分享
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes;
function custom_sort(List: TStringList; Index1, Index2: Integer): Integer;
begin
if Length(List[index1]) < Length(List[index2]) then
begin
Result := -1;
Exit;
end
else if Length(List[index1]) > Length(List[index2]) then
begin
Result := 1;
Exit;
end;
Result := AnsiCompareStr(List[index1], List[index2]);
end;
var
t: TStringList;
i: Integer;
begin
t := TStringList.Create;
try
t.add('abc1');
t.add('abc2');
t.add('abc30');
t.add('abc4');
t.add('abc10');
t.add('abc11');
t.CustomSort(custom_sort);
for i := 0 to t.Count - 1 do
begin
Writeln(t[i]);
end;
finally
t.Free;
end;
Readln;
end.