implementationuses StrUtils;{$R *.dfm}{$DEFINE Debug}type PPilv= ^Pilv
Pilv=record chr: Char
times: Integer
idx: Integer; //not used end;var pArray: array[0..9] of PPilv
iArray: array[0..9] of Pilv;procedure BubbleSort;var i, j: Integer
ptmp: PPilv;begin for i := 0 to 9 do begin pArray:= @iArray
end
for i := 0 to 9 do begin for j := i to 9 do begin if( pArray^.times> pArray[j]^.times) then begin ptmp:= pArray
pArray:= pArray[j]
pArray[j]:= ptmp
end
end
end
for i := 0 to 9 do begin for j := i to 9 do begin if((pArray^.times= pArray[j].times)and(pArray.chr> pArray[j].chr)) then begin ptmp:= pArray
pArray:= pArray[j]
pArray[j]:= ptmp
end
end
end;end;procedure PrintStr;var i, j: Integer
str: string;begin for i := 0 to 9 do begin for j := 1 to pArray.times do begin str:= str+ pArray.chr
end
end
ShowMessage(ReverseString(str));end
procedure Clear;var i: Integer
stmp: string
//for debugbegin stmp:= ''
{$IFDEF Debug} for i := 0 to 9 do begin stmp:= stmp+ ' '+ pArray.chr+ ':'+ IntToStr(pArray^.times)
end
ShowMessage(stmp)
{$ENDIF} for i := 0 to 9 do begin iArray.times:= 0
iArray.idx:= 0
end;end;procedure TForm1.btnExitClick(Sender: TObject);begin Close;end;procedure TForm1.FormCreate(Sender: TObject);var i: Integer;begin for i := 0 to 9 do begin pArray:= nil
iArray.times:= 0
iArray.idx:= 0
iArray.chr:= Char(i + $30)
end;end;procedure TForm1.btnActionClick(Sender: TObject);var str: string
i, n: Integer;begin str:= edt1.Text
for i := 0 to Length(str)-1 do begin n:= ord(str[i + 1]) - $30
Inc(iArray[n].times)
end
BubbleSort
PrintStr
Clear;end;end.定义了一个TEdit: edt1, 一个TButton: btnExit,一个TButton: btnAction。