我想将5个int数排序,不知是否有这样的函数。我不想用冒泡排序,麻烦。
如果一个函数就完成,不是更简结吗。

解决方案 »

  1.   

    多线程冒泡排序使用了DELPHI提供的TThread类。
      一.基本的方法如下:  1.从Tthread类派生一个新类。(创建TSortThread类)
      2.定义新类的Create方法。
      3.定义新类的Execute方法,并在Execute方法中插入线程运行时执行的代码。
      4.引用类方法创建实例。
      二.例子的详细代码及说明:
      首先,新建一个单元,保存为mysort.pas.在此单元中,我们创建了一个TSortThread类,它从TThread类中继承而来,所以当我们在程序中创建这个类的一个实例时,也就是创建了一个新的线程。
      接着,在该类中定义一个Sort方法,用来对数组进行排序,同时TSortThread类超越了TThread类的构造方法Create和Execute,在execute方法中,调用了对数组进行排序的Sort方法。具体代码如下:  unitmysort;
      interface
      usesClasses;//TThread类在Classes中被定义。
      type
      PSortArray=TSortArray;
    TSortArray=array.[0..MaxIntdivSize
    Of(Integer)-1]ofInteger;
      {此处定义了TsortThread类}
      TSortThread=class(TThread)
      Private
      {在TSortThread类中定义了如下几个私有变元}
      FSortArray:PSortArray;
      FSize:Integer;
      FA,FB,FI,FJ:Integer;
      Protected
      {类TSortThread超越了类Tthread的Execute方法}
      procedure Execute;override;
      {类TsortThread添加了一个Sort方法}
      procedure Sort(varA:arrayofInteger);  public
      {类TSortThread超越了类Tthread的构造方法}
      constructorCreate(varSortArray:arrayofInteger);
      end;
      implementation
      constructorTSortThread.Create(varSortArray:arrayofInteger);
      begin
      FSortArray:=@SortArray;
      FSize:=High(SortArray)-Low(SortArray)+1;
      FreeOn Terminate:=True;
      inheritedCreate(False);
      end;
      {当线程开始时,Execute方法将被调用。}
      procedure TSortThread.Execu
    te;
      begin
      Sort(Slice(FSortArray,FSize));
      end;
      {下面实现了冒泡法排序}
      procedure TSortThread.Sort(varA:arrayofInteger);  var
      I,J,T:Integer;
      begin
      for I:=High(A)downto Low(A) do
      for J:=Low(A)to High(A)-1 do
      if A[J]>A[J+1] then
      begin
      T:=A[J];
      A[J]:=A[J+1];
      A[J+1]:=T;
      if Terminated then Exit;
      end;
      end;
      end
      最后,在用户应用程序的implementation处加入usesmysort,在执行排序的地方加入TQuickSortthread.Create(SortArray),其中SortArray为一实际的数组。这样就可以用线程实现排序,在排序过程中,用户不必等到排序结束就可以执行其它操作。这种用多线程实时响应用户操作方法在涉及大量数据处理的应用程序中显得尤为重要。
      

  2.   

    allan2002(丸子) 的很詳細.學習ing!
      

  3.   

    用TlistBox或TCombobox控件吧,只要设置属性Sorted为True它就会自动排序。
      

  4.   

    在DELPHI的例程中有一个多线程的例子,就是说排序的..你可以小参考一下..
      

  5.   

    没错,在  .. \demo\thread下有现成的。
      

  6.   

    用TLIST类里面有快速排序的函数,看一下就知道了。
      

  7.   

    可用TstringList,有一个sort方法,还可自定义sort,或在一个varinat单元中有很多数组的原型,定义了很多排序算法