(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
unit QS;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure QuickSort(iLo, iHi: Integer);
    procedure ListBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
   QuickSort(0, 9);
end;

procedure Tform1.QuickSort(iLo, iHi: Integer);

var
  Lo, Hi: Integer;
  mid:real;
  T:string;

begin
  Lo := iLo;
  Hi := iHi;
  Mid :=strtofloat(ListBox1.items[(lo+hi) div 2]);
    repeat
    while strtofloat(ListBox1.items[lo])< Mid do Inc(Lo);
    while strtofloat(ListBox1.items[hi])> Mid do Dec(Hi);
    if Lo <= Hi then
    begin
      T := ListBox1.items[lo];
      ListBox1.items[lo]:=ListBox1.items[Hi];
      ListBox1.items[Hi]:= T;
      Inc(Lo);
      Dec(Hi);
    end;
  until Lo > Hi;
  if Hi > iLo then QuickSort(iLo, Hi);
  if Lo < iHi then QuickSort(Lo, iHi);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
end;

end.
