function m(k:array of integer):integer;
type
Pr=^tr;
tr=record
num:Integer;
Cou:Integer;
end;
var
l:TList;
rr;
i,j:integer;
H:boolean;
begin
l:=TList.Create;
for i:=0 to high(k) do
begin
h:=True;
for j:=0 to l.Count-1 do
if tr(l.Items[j]^).num = k then
begin
inc(tr(l.Items[j]^).Cou);
h:=False;
Break;
end;
if h then
begin
new(r);
r^.num :=k;
r^.Cou :=1;
l.Add(r);
end;
end;
for i:=0 to l.Count-1 do
begin
r:=l.Items;
showmessage('数字'+inttostr(r^.num)+'出现了'+inttostr(r^.Cou)+'次');
Dispose(r);
end;
l.Free;
end;
//過程F是顯示一個數組中第一個重復次數最多的數和次數
procedure F( A:Array of integer);
var i,j,n,c,val:integer;
begin
c:=0;
n:=1;
val:=A[low(A)];
for i:=low(A) to high(A) do
begin
for j:=i+1 to high(A) do
begin
if A=A[j] then
inc;
end;
if n>c then
begin
c:=n;
val:=A;
end;
n:=1;
end;
ShowMessage('出現次數最多的數是'+IntToSTr(val)+' 次數是'+IntToSTr(c));
end;
//下面是調用F(B)
procedure TForm1.Button1Click(Sender: TObject);
const B:Array[1..10] of Integer=(5,6,5,2,5,8,9,14,78,105);
begin
F(B);
end;
//可以通過傳遞其它的數組來得到結果