Скачиваний:
13
Добавлен:
15.06.2014
Размер:
2.19 Кб
Скачать
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
ListBox1: TListBox;
ListBox2: TListBox;
Memo1: TMemo;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
BitBtn1: TBitBtn;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);


private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
spt1:Tsp;
sp1:Tsel;
s,f:integer;
l,m:extended;
sum,min,max,N,imax,imin,o:integer;
implementation

{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
ListBox1.Clear;
ListBox2.Clear;
l:=0;
m:=0;
sp1:=nil;
randomize;
for i:=1 to 12 do begin
s:=Random(100)+1;
l:=l+s;
spt1.AddS(sp1,s);
with ListBox1 do
begin
Items.Add(IntToStr(s));
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var pt:Tsel;
begin
min:=sp1.a^.inf;
max:=sp1.a^.inf;
N:=6;
imin:=5;
imax:=5;
o:=0;
if sp1=nil then ShowMessage('Стек пуст')
else repeat
s:=sp1^.inf;
pt:=sp1;
if min>=sp1^.inf then begin
min:=sp1^.inf;
imin:=N-o;
end;
if max<=sp1^.inf then begin
imax:=N-o;
max:=sp1^.inf;
end;
m:=m+sqr(s-l/6);
inc(o);
sp1:=sp1^.a;
Dispose(pt);
until sp1=nil;
sum:=imax-imin;
Memo1.Lines.Add(IntTostr(max)+'-max'+' '+IntTostr( min)+'-min'+' '+
'расстояние='+FloatToStr(abs(sum)-1));
end;

procedure TForm1.Button3Click(Sender: TObject);
var pt:Tsel;
begin
spt1.SS(sp1);
while sp1<>nil do begin
if sp1<>nil then begin
pt:=sp1;
f:=sp1^.inf;
sp1:=sp1^.a;
Dispose(pt);
end else f:=0;
with ListBox2 do
Items.Add(IntToStr(f));
end;
end;


procedure TForm1.Button4Click(Sender: TObject);
begin
ListBox1.Clear;
ListBox2.Clear;
Memo1.Clear;
end;

end.
Соседние файлы в папке максимальный, минимальный