Скачиваний:
6
Добавлен:
01.05.2014
Размер:
2.99 Кб
Скачать
program ex017;
uses crt;
type
TFileText=text;

List=^ListStr;
ListStr=record
Info: String;
Next,Prev:List;
end;
{*********************************************}
procedure AddToList(X: string; var PEndList:List);
begin
if PEndList=nil then
begin
New(PEndList);
PEndList^.Info:=X;
PEndList^.Next:=nil;
PEndList^.Prev:=nil;
end
else
begin
New(PEndList^.Next);
PEndList^.Prev:=PEndList;
PEndList:=PEndList^.Next;
PEndList^.Info:=X;
PEndList^.Next:=nil;
end;
end;
{*************************************}
Function CreateLists(var q: List; max:longint):List;
var
i:longint;
X: string;
Uk,ListBegin:List;
begin
X:='';
Uk:=nil;
q:=nil;
AddToList(X,Uk);
q:=Uk;
for i:=1 to max-1 do
begin
X:='';
AddToList(X,q);
end;
ListBegin:=Uk;
CreateLists:=ListBegin;
end;
{***************************************}
procedure ShowFile(f1:string; i:longint);
var
inF: TFileText;
Str: string;
a:longint;
begin
assign(inF,f1);
{$I-}
reset(inF);
if ioresult<>0 then begin write('File not found!'); exit; end;
{$I+}
for a:=1 to i do
begin
readln(inF,Str);
writeln (Str);
end;
close(inF);
end;
{*****************************************}
function RandomFill(f1:string):longint;
var
i:longint;
inF: TFileText;
s:string;
begin
randomize;
assign(inF,f1);
{$I-}
reWrite(inF);
if ioresult<>0 then begin write('Can not create file!'); exit; end;
{$I+}
i:=1;
for i:=1 to random(10) do
begin
s:='';
while length(s)<=5+random(20) do
begin
s:=s+chr(ord('a')+random(26));
end;
writeln(inF,s);
end;
Close(inF);
ShowFile(f1,i);
randomFill:=i;
end;
{******************************************}
procedure ex17(S1,S2: string);
var
inF,outF: TFileText;
ListTmp,L1,L2,LEnd: List;
Str: string;
i:longint;
begin
i:=RandomFill(S1);
ListTmp:=nil;
assign(inF,S1);
assign(outF,S2);
{$I-}
reset(inF);
if ioresult<>0 then begin write('File not found!'); exit; end;
reWrite(outF);
if ioresult<>0 then begin write('Can not create file!'); exit; end;
{$I+}
if i=0 then writeln('File = Nill!');
L1:=CreateLists(ListTmp,i);
ListTmp:=L1;
L2:=L1^.Next;
while not EOF(inF) do
begin
readln(inF,str);
ListTmp^.Info:=str;
ListTmp:=L2;
L2:=ListTmp^.Prev;
end;
while ListTmp=nil do
begin
LEnd:=L2;
readln(inF,str);
L2:=ListTmp;
ListTmp:=ListTmp^.Prev;
writeln(outF, L2^.Info);
L2:=L2^.Prev;
end;

{ListTmp:=L1;
while not EOF(inF) do
begin
ListTmp:=L2;
readln(inF,str);
ListTmp^.Info:=str;
L2:=ListTmp^.Next;
end;

while ListTmp^.Next<>nil do
begin
str:='';
writeln(outF,ListTmp^.Info);
ListTmp^.Next:=ListTmp;
end;}
writeln('****************');
ShowFile(S2,i);
close(inF);
close(outF);
end;
{******************************************}

const
S2='ex1702.txt';
S1='ex1701.txt' ;
begin
clrscr;
randomize;
{RandomFill(S1); }
ex17(S1,S2);
{CreateLists(5);}
end.
Соседние файлы в папке Вопросы к экзамену с ответами и демо-программами на Паскале