现已有数组data,我想以 lin_t的location来排序产生data1数组,请问各位怎样用排序算法实现??????
type
lin_t = packed record
eqnum : string;
edescription : string;
location : string;
ldescription : string;
installdate : string;
purchaseprice : double; end;
var
data:array of lin_t
type
lin_t = packed record
eqnum : string;
edescription : string;
location : string;
ldescription : string;
installdate : string;
purchaseprice : double; end;
var
data:array of lin_t
type
lin_t = packed record
eqnum : string;
edescription : string;
location : string;
ldescription : string;
installdate : string;
purchaseprice : double;
procedure.... end;
var
data:array of lin_t
var
List: TList;
i: integer;
begin
List := TList.Create;
List.
try
for i:=0 to Length(data)-1 do begin
List.Add(&data[i]);
end;
List.Sort(_Compare)
finally
List.Free;
end;
end;function _Compare(Item1, Item2: Pointer): Integer;
var
loc1,loc2: integer;
begin
loc1 := StrToInt(lin_t(item1).location);
loc2 := StrToInt(lin_t(item2).location);
result := loc1-loc2;
end;
var
DataNew: array of lin_t;
pp: lin_t;
begin
setLength(DataNew, Lenght(Data));
for i:=0 to List.count-1 do begin
pp := List[i];
DataNew[i].eqnum := pp.eqnum;
...
DataNew[i].purchaseprice := pp.purchaseprice;
end;
end;
有没有需要时间更少的排序方法(是针对上面的问题的)呢?