现已有数组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

解决方案 »

  1.   

    ????????????
    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
      

  2.   

    用TList的Sort方法,使用的是quicksort的算法
    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;
      

  3.   

    忘了把排过序的list写回data数组了,你自己搞定吧。
    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;
      

  4.   

    那请问data中有14083条数据,大概要多久能排好序呢?
    有没有需要时间更少的排序方法(是针对上面的问题的)呢?