Код
program listexample;
uses CRT;
type
plist = ^tlist;
p2list = ^plist;
tlist = record
datai:integer;
next, prev:plist;
end;
type cc = class
private
cclist:plist;
public
procedure display();
procedure addToEnd (list:p2list; d:integer);
procedure delFromBegin(list:p2list);
procedure findData(list:p2list; datai:integer);
end;
procedure cc.display();
var
p:plist;
begin
if cclist = nil then
writeLn ('List cleaning')
else
begin
p := cclist;
while p^.prev <> nil do
p := p^.prev;
while p <> nil do
begin
if p = cclist then
write('*', ' ')
else
write(' ');
writeln(p^.datai);
p := p^.next
end
end
end;
procedure cc.addToEnd (list:p2list; d:integer);
var
prior:plist;
begin
prior := nil;
while list^ <> nil do
begin
prior := list^;
list := @list^^.next
end;
New (list^);
with list^^ do
begin
datai := d;
next := nil;
prev := prior
end
end;
procedure cc.delFromBegin(list:p2list);
begin
if list^ = nil then
exit;
if list^^.next <> nil then
begin
list^ := list^^.next;
list^^.prev := list^^.prev^.prev;
if list^^.prev <> nil then
list^^.prev^.next := list^;
end
else
if list^^.prev <> nil then
begin
list^ := list^^.prev;
list^^.next := list^^.next^.next;
if list^^.next <> nil then
list^^.next^.prev := list^;
end
else
list^ := nil;
end;
procedure cc.findData(list:p2list; datai:integer);
var
l:plist;
begin
if list^ = nil then
begin
exit;
end;
while list^^.prev <> nil do
list^ := list^^.prev;
l := list^;
while l <> nil do
begin
if l^.datai = datai then
begin
list^ := l;
exit;
end;
l := l^.next
end;
end;
var
clist:cc;
i:integer;
begin
while true do
begin
ClrScr;
writeLn('1 - Add to end');
writeLn('2 - Find data');
writeLn('3 - Delete begin');
writeLn('0 - Exit');
writeLn('>>>>');
writeln(#10, 'List: ');
clist.display();
gotoxy(5, 5);
Readln(i);
case i of
1:
begin
write('Enter number: ');
readLn(i);
clist.addToEnd(@clist.cclist, i);
end;
2:
begin
write('Enter number: ');
readLn(i);
clist.findData(@clist.cclist, i);
end;
3:
clist.delFromBegin(@clist.cclist);
0:
break;
end;
end;
end.
uses CRT;
type
plist = ^tlist;
p2list = ^plist;
tlist = record
datai:integer;
next, prev:plist;
end;
type cc = class
private
cclist:plist;
public
procedure display();
procedure addToEnd (list:p2list; d:integer);
procedure delFromBegin(list:p2list);
procedure findData(list:p2list; datai:integer);
end;
procedure cc.display();
var
p:plist;
begin
if cclist = nil then
writeLn ('List cleaning')
else
begin
p := cclist;
while p^.prev <> nil do
p := p^.prev;
while p <> nil do
begin
if p = cclist then
write('*', ' ')
else
write(' ');
writeln(p^.datai);
p := p^.next
end
end
end;
procedure cc.addToEnd (list:p2list; d:integer);
var
prior:plist;
begin
prior := nil;
while list^ <> nil do
begin
prior := list^;
list := @list^^.next
end;
New (list^);
with list^^ do
begin
datai := d;
next := nil;
prev := prior
end
end;
procedure cc.delFromBegin(list:p2list);
begin
if list^ = nil then
exit;
if list^^.next <> nil then
begin
list^ := list^^.next;
list^^.prev := list^^.prev^.prev;
if list^^.prev <> nil then
list^^.prev^.next := list^;
end
else
if list^^.prev <> nil then
begin
list^ := list^^.prev;
list^^.next := list^^.next^.next;
if list^^.next <> nil then
list^^.next^.prev := list^;
end
else
list^ := nil;
end;
procedure cc.findData(list:p2list; datai:integer);
var
l:plist;
begin
if list^ = nil then
begin
exit;
end;
while list^^.prev <> nil do
list^ := list^^.prev;
l := list^;
while l <> nil do
begin
if l^.datai = datai then
begin
list^ := l;
exit;
end;
l := l^.next
end;
end;
var
clist:cc;
i:integer;
begin
while true do
begin
ClrScr;
writeLn('1 - Add to end');
writeLn('2 - Find data');
writeLn('3 - Delete begin');
writeLn('0 - Exit');
writeLn('>>>>');
writeln(#10, 'List: ');
clist.display();
gotoxy(5, 5);
Readln(i);
case i of
1:
begin
write('Enter number: ');
readLn(i);
clist.addToEnd(@clist.cclist, i);
end;
2:
begin
write('Enter number: ');
readLn(i);
clist.findData(@clist.cclist, i);
end;
3:
clist.delFromBegin(@clist.cclist);
0:
break;
end;
end;
end.
P.S. Заранее благодарю!!!