uses Crt type list item item record data integer next list end var las

 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
60
uses Crt;
type list = ^item;
item = record
data:integer;
next:list;
end;
var lastptr,newptr,first,current,last:list;
procedure initList;
var x:integer;
begin
last:=nil;
readln(x);
while x <> 0 do
begin
new(current);
current^.data:=x;
current^.next:=nil;
if (last = nil) then
first:=current
else last^.next:=current;
last:=current;
readln(x);
end;
end;
procedure newlist;
begin
current:=first;
lastptr:=nil;
while current <> nil do
begin
new(newptr);
newptr^.data:=current^.data;
newptr^.next:=lastptr;
current:=current^.next;
lastptr:=newptr;
end;
end;
procedure print;
begin
current:=first;
while current <> nil do
begin
write(current^.data, ' ');
current:=current^.next;
end;
end;
procedure connect;
begin
current:=last;
current^.next:=newptr;
end;
Begin
clrscr;
first:=nil;
initList;
newList;
connect;
print;
readkey;
End.