дана программа, надо помочь выяснить что в ней делает каждая подпрограмма
Код:
unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMainForm = class(TForm)
Button1: TButton;
GroupBox2: TGroupBox;
Memo2: TMemo;
GroupBox3: TGroupBox;
Memo3: TMemo;
GroupBox4: TGroupBox;
Memo4: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Ptr = ^rec;
rec = record
key,key1 : integer;
next : ptr;
end;
Queue=record
head,tail:Ptr;
end;
var
MainForm: TMainForm;
t:rec;
implementation
{$R *.dfm}
procedure InQueue(var aQueue:Queue; var aPElem:Ptr);
begin
if aPElem=nil then Exit;
aPElem^.Next:=nil;
With aQueue do begin
if head=nil then head:=aPElem
else tail^.next:=aPElem;
tail:=aPElem;
end;
end;
function PQueue(var aQueue:Queue; var aPElem:Ptr):Boolean;
begin
Result:=False;
if aQueue.head=nil then Exit;
With aQueue do begin
aPElem:=head;
head:=aPElem^.Next;
if head=nil then tail:=nil;
Result:=True;
end;
end;
procedure TMainForm.Button1Click(Sender: TObject);
var
Top1,Top2,Top3 : Queue;
PElem1,PElem2,pe1,pe2 : Ptr;
i,a,b,ind : Integer;
s,inputS : string;
f : TextFile;
Flag : boolean;
begin
memo2.Clear;
memo3.Clear;
memo4.Clear;
AssignFile(f,'ќчередь.txt');
reset(f);
With Top1 do begin
head:=nil;
tail:=nil;
end;
With Top2 do begin
head:=nil;
tail:=nil;
end;
With Top3 do begin
head:=nil;
tail:=nil;
end;
Flag:=True;
While Not eof(f) do begin
Readln(f,s);
Repeat
New(PElem1);
ind:=Pos(',',s);
a:=StrToInt(Copy(s,1,ind-1));
Delete(s,1,ind);
ind:=Pos(';',s);
If ind=0 then ind:=Pos('|',s);
b:=StrToInt(Copy(s,1,ind-1));
Delete(s,1,ind);
PElem1^.key:=a;
PElem1^.key1:=b;
If Flag=True then InQueue(top1,PElem1)
else InQueue(top2,PElem1)
until s='';
Flag:=False;
end;
While PQueue(Top1,PElem1) do begin
inputS:=IntToStr(PElem1.key);
If s<>'' then
If InputS[1]<>'-' then s:=s+'+'+inputS+'*x^'+IntToStr(PElem1.key1)
else s:=s+inputS+'*x^'+IntToStr(PElem1.key1)
else s:=InputS+'*x^'+IntToStr(PElem1.key1);
end;
memo2.Lines.Add(s);
s:='';
While PQueue(Top2,PElem1) do begin
inputS:=IntToStr(PElem1.key);
If s<>'' then
If InputS[1]<>'-' then s:=s+'+'+inputS+'*x^'+IntToStr(PElem1.key1)
else s:=s+inputS+'*x^'+IntToStr(PElem1.key1)
else s:=InputS+'*x^'+IntToStr(PElem1.key1);
end;
memo3.Lines.Add(s);
s:='';
closeFile(f);
Flag:=False;
Repeat
New(PE1);
New(PE2);
If not PQueue(Top1,PE1) then flag:=True;
If not PQueue(Top2,PE2) then flag:=True;
PQueue(Top1,PE1);
PQueue(Top2,PE2);
If pe1.key1<Pe2.key1 then begin
InQueue(Top3,pe1);
InQueue(Top3,pe2);
end
else begin
InQueue(Top3,pe2);
InQueue(Top3,pe1);
end;
If pe1.key1=Pe2.key1 then begin
pe1.key:=pe1.key+pe2.key;
InQueue(Top3,Pe1);
end;
until Flag=True;;
While PQueue(Top3,PElem1) do begin
inputS:=IntToStr(PElem1.key);
If s<>'' then
If InputS[1]<>'-' then s:=s+'+'+inputS+'*x^'+IntToStr(PElem1.key1)
else s:=s+inputS+'*x^'+IntToStr(PElem1.key1)
else s:=InputS+'*x^'+IntToStr(PElem1.key1);
end;
memo4.Lines.Add(s);
end;
end.