Добавил:
Kaz
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label2: TLabel;
Edit3: TEdit;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
Tinf=record
k:integer;
{ a:array[1..10]of byte;}
end;
psel=^sel;
sel=record
inf:Tinf;
A:psel;
end;
TList=class(tObject)
sp1,sp:psel;
constructor Create;
procedure Addl(inf:Tinf);
procedure Print;
procedure Podschet;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
stec:TList;
inf:Tinf;
max,n,m,i,j:integer;
s:string;
a:array[1..10]of byte;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
for j:=1 to 10 do begin
a[j]:=0;
end;
listbox1.Clear;
m:=strtoint(edit3.Text);
stec.Free;
randomize;
stec:=TList.Create;
for i:=1 to m do begin
inf.k:=(random(10)+1);
stec.Addl(inf);
listbox1.Items.Add(inttostr(inf.k));
end;
stec.Print;
stec.Podschet;
edit1.text:=inttostr(n);
edit2.text:=inttostr(max);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
listbox1.Clear;
m:=strtoint(edit3.text);
edit1.text:='';
edit2.Text:='';
end;
constructor TList.Create;
begin
Inherited Create;
sp1:=nil;
end;
procedure TList.Addl(inf:Tinf);
begin
if sp1=nil then begin
new(sp1);
sp1^.A:=nil;
sp1^.inf:=inf;
end
else begin
new(sp);
sp^.A:=sp1;
sp^.inf:=inf;
sp1:=sp;
end;
end;
Procedure Tlist.Print;
begin
sp:=sp1;
While sp<>Nil do begin
for j:=1 to 10 do begin
if sp^.inf.k=j then begin
a[j]:=a[j]+1;
end
end;
sp:=sp^.A;
end;
end;
procedure Tlist.Podschet;
begin
n:=0;
sp:=sp1;
max:=0;
While sp<>Nil do begin
for j:=1 to 10 do begin
if max<=a[j]then begin
max:=a[j];
n:=j;
end;
end;
sp:=sp^.A;
end;
{sp:=sp1;
s:=inttostr(n);
While sp<>Nil do begin
for j:=1 to 10 do begin
if max=a[j]then begin
s:=s+', '+inttostr(j);
end;
end;
sp:=sp^.A;
end;}
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label2: TLabel;
Edit3: TEdit;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
Tinf=record
k:integer;
{ a:array[1..10]of byte;}
end;
psel=^sel;
sel=record
inf:Tinf;
A:psel;
end;
TList=class(tObject)
sp1,sp:psel;
constructor Create;
procedure Addl(inf:Tinf);
procedure Print;
procedure Podschet;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
stec:TList;
inf:Tinf;
max,n,m,i,j:integer;
s:string;
a:array[1..10]of byte;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
for j:=1 to 10 do begin
a[j]:=0;
end;
listbox1.Clear;
m:=strtoint(edit3.Text);
stec.Free;
randomize;
stec:=TList.Create;
for i:=1 to m do begin
inf.k:=(random(10)+1);
stec.Addl(inf);
listbox1.Items.Add(inttostr(inf.k));
end;
stec.Print;
stec.Podschet;
edit1.text:=inttostr(n);
edit2.text:=inttostr(max);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
listbox1.Clear;
m:=strtoint(edit3.text);
edit1.text:='';
edit2.Text:='';
end;
constructor TList.Create;
begin
Inherited Create;
sp1:=nil;
end;
procedure TList.Addl(inf:Tinf);
begin
if sp1=nil then begin
new(sp1);
sp1^.A:=nil;
sp1^.inf:=inf;
end
else begin
new(sp);
sp^.A:=sp1;
sp^.inf:=inf;
sp1:=sp;
end;
end;
Procedure Tlist.Print;
begin
sp:=sp1;
While sp<>Nil do begin
for j:=1 to 10 do begin
if sp^.inf.k=j then begin
a[j]:=a[j]+1;
end
end;
sp:=sp^.A;
end;
end;
procedure Tlist.Podschet;
begin
n:=0;
sp:=sp1;
max:=0;
While sp<>Nil do begin
for j:=1 to 10 do begin
if max<=a[j]then begin
max:=a[j];
n:=j;
end;
end;
sp:=sp^.A;
end;
{sp:=sp1;
s:=inttostr(n);
While sp<>Nil do begin
for j:=1 to 10 do begin
if max=a[j]then begin
s:=s+', '+inttostr(j);
end;
end;
sp:=sp^.A;
end;}
end;
end.