题设如下:
   有一个有序集合A(集合元素很多),想在这个有序集合里插入数据(插入的数据个数很多),我想实现的功能是:查找集合A当中是否有该数据,如果没有,则插入,我选择的方法是:首先折半查找,如果没有再插入,这里出现个问题:折半查找存储要用顺序存储,但是大量插入数据操作的存储方式最好是链表,我在google搜索到一篇文章说:Tlist既可以当顺序表用,也可以当链表用,我想问问是否如此,Tlist是怎么存储数据的?谢谢各位大侠。

解决方案 »

  1.   

    TList就是一个链表,而且当然是有顺序的.
    要快速查找的话,建以用一个Hash做个索引表专门查询.
      

  2.   

    delphi的例子参考:
    This example creates a list object and inserts two records into it. The value of the record fields are written on a paintbox:procedure TForm1.FormButton1Click(Sender: TObject);type
      PMyList = ^AList;
      AList = record
        I: Integer;
        C: Char;
      end;var  MyList: TList;
      ARecord: PMyList;
      B: Byte;
      Y: Word;
    begin
      MyList := TList.Create;
      try
        New(ARecord);
        ARecord^.I := 100;
        ARecord^.C := 'Z';
        MyList.Add(ARecord); {Add integer 100 and character Z to list}
        New(ARecord);
        ARecord^.I := 200;
        ARecord^.C := 'X';
        MyList.Add(ARecord); {Add integer 200 and character X to list}    { Now paint the items onto the paintbox}
        Y := 10;             {Variable used in TextOut function}    for B := 0 to (MyList.Count - 1) do
        begin
          ARecord := MyList.Items[B];
          Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
          Y := Y + 30;  {Increment Y Value again}
          Canvas.TextOut(10, Y, ARecord^.C);  {Display C}
          Y := Y + 30;  {Increment Y Value}
        end;    { Cleanup: must free the list items as well as the list }
       for B := 0 to (MyList.Count - 1) do
       begin     ARecord := MyList.Items[B];
         Dispose(ARecord);
       end;
      finally
        MyList.Free;
      end;
    end;
      

  3.   

    谢谢楼上几位,那如果用Tstringlist能实现吗?
      

  4.   


    可以的,用TStringList的Objects......