Скачиваний:
4
Добавлен:
01.05.2014
Размер:
1.92 Кб
Скачать
{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T+,V+,X+,Y+}
{$M 16384,0,655360}
program GalkaVV;
uses crt;
type
TText=text;
PListItem=^TListItem;
TListItem=record
Data:string;
Next:PListItem;
end;

PFIFO=^TFIFO;
TFIFO=object
private
AList,BList:PListItem;
public
constructor Init;
destructor Done;
procedure Put(Element: string);
function Get:string;
function NotEmpty:boolean;
end;

constructor TFIFO.Init;
begin
AList:=Nil;
BList:=Nil;
end;

destructor TFIFO.Done;
var
P:PListItem;
begin

while AList<>Nil do
begin
P:=AList^.Next;
Dispose(AList);
AList:=P;
end;
end;


function TFIFO.Get:string;
var
P:PListItem;
GetData: string;
begin
if AList=Nil then begin Get:=''; exit; end;
P:=AList^.Next;
GetData:=AList^.Data;
Dispose(AList);
AList:=P;
if AList=nil then BList:=AList;
Get:=GetData;
end;

Procedure TFIFO.Put(Element: string);
var
P: PListItem;
begin
New(P);
P^.Data:=Element;
if (BList=nil) and (AList=nil) then
begin
P^.Next:=nil;
AList:=P;
BList:=P;
end
else
begin
BList^.Next:=P;
P^.Next:=nil;
BList:=P;
end;
end;

function TFIFO.NotEmpty;
begin
NotEmpty:=AList<>nil;
end;


procedure Change(s1,s2:string; var AFIFO:PFIFO);
var
Tmp:PListItem;
p:byte;
begin
Tmp:=AFIFO^.AList;
while Tmp<>nil do
begin
p:=pos(s1,Tmp^.Data);
while p<>0 do
begin
delete(Tmp^.Data,p,length(s1));
insert(s2,Tmp^.Data,p);
p:=pos(s1,Tmp^.Data);
end;
Tmp:=Tmp^.Next;
end;
end;

var
FiFo:PFIFO;
Tmp:PListItem;
str1,str2: string;
begin
clrscr;
New(FiFo,Init);
str1:='g';
str2:='BB';
Tmp:=FiFo^.AList;
FIFO^.put('sggasrger');
FIFO^.put('lksjrgla');
FIFO^.put('aoirugj');
FIFO^.put('ksagjh8848ujh');
Change(str1,str2,FiFo);
while Fifo^.AList<>nil do
begin
writeln(FiFo^.Get);
end;
Dispose(FiFo,Done);
end.
Соседние файлы в папке Вопросы к экзамену с ответами и демо-программами на Паскале