uses Crt type ptr item item record data string prev ptr next ptr end v

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
uses Crt;
type ptr = ^item;
item = record
data:string;
prev:ptr;
next:ptr;
end;
var head,last,current,prev:ptr;
q:string;
f:text;
procedure insertLast;
begin
assign(f,'file.txt');
reset(f);
while not eof(f) do
begin
new(current);
readln(f,current^.data);
current^.next:=nil;
if last = nil then head := current else last^.next:=current;
last:=current;
end;
end;
procedure printList;
begin
current:=head;
while current <> nil do
if pos((current^.next)^.data,q) <> 0 then
begin
write((current^.next)^.data,' ');
prev:=current;
current:=current^.next;
prev^.next:=current^.next;
dispose(current);
current:=prev;
end
else current:=current^.next;
end;
procedure print;
begin
current:=head;
while current <> nil do
begin
write(current^.data,' ');
current:=current^.next;
end;
writeln;
end;
Begin
clrscr;
head:=nil;
last:=nil;
q:='for do while begin else';
insertLast;
printList;
print;
readkey;
End.