Memo1
ss 0 毫秒
QuickSortStr 951 毫秒
ss 0 毫秒
QuickSortStr 941 毫秒
ss 0 毫秒
QuickSortStr 951 毫秒
ss 0 毫秒
QuickSortStr 951 毫秒
ss 0 毫秒
QuickSortStr 952 毫秒
ss 0 毫秒
QuickSortStr 961 毫秒
ss 0 毫秒
QuickSortStr 961 毫秒
ss 0 毫秒
QuickSortStr 952 毫秒
ss 0 毫秒
QuickSortStr 951 毫秒
测试程序
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
data: string;
implementation
{$R *.dfm}
function QuickSortStr(S: string): string;
procedure QuickSort(L, H: Integer);
var I, J: Integer;
X: Char;
begin
if L >= H then Exit;
I := L
J := H
X := S;
while (I <> J) do
begin
while (I < J) and (S[J] > X) do Dec(J);
if I < J then begin S := S[J]
Inc(I)
end;
while (I < J) and (S <= X) do Inc(I);
if I < J then begin S[J] := S
Dec(J)
end;
S := X;
QuickSort(L, I - 1);
QuickSort(I + 1, H);
end;
end;
begin
QuickSort(1, Length(S));
Result := S;
end;
function ss(v: string): string;
var
data: array['A'..'Z'] of integer;
i: Integer;
c: char;
str: string;
begin
FillChar(data, length(data) * 4, 0);
for i := 1 to length(V) do
inc(data[V]);
result := '';
for c := 'A' to 'Z' do
if data[C] > 0 then
begin
setLength(str, data[C]);
FillChar(str[1], data[C], C);
result := result + str;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
c: CHAR;
begin
for C := 'A' to 'Z' do
Data := DATA + C;
Data := Data + Data;
Data := Data + Data;
Data := Data + Data;
Data := Data + Data;
Data := Data + Data;
Data := Data + Data;
{ Data := Data + Data;
Data := Data + Data;
Data := Data + Data;
Data := Data + Data;
}
end;
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
b: integer;
begin
b := GetTickCount;
S := ss(Data);
memo1.Lines.Add(format('ss %D 毫秒', [GetTickCount - b]));
b := GetTickCount;
S := QuickSortStr(Data);
memo1.Lines.Add(format('QuickSortStr %D 毫秒', [GetTickCount - b]));
end;
end.