Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,75 @@
type Node<T> = auto class
data: T;
prev,next: Node<T>;
end;
type
MyLinkedList<T> = class
first, last: Node<T>;
procedure AddFirst(x: T);
begin
if first = nil then
begin
first := new Node<T>(x,nil,nil);
last := first
end
else
begin
var p := new Node<T>(x,nil,first);
first.prev := p;
first := p;
end;
end;
procedure AddLast(x: T);
begin
if first = nil then
begin
first := new Node<T>(x,nil,nil);
last := first
end
else
begin
var p := new Node<T>(x,last,nil);
last.next := p;
last := p;
end;
end;
procedure AddAfter(p: Node<T>; x: T);
begin
if last = p then
AddLast(x)
else begin
var pp := new Node<T>(x,p,p.next);
p.next := pp;
pp.next.prev := pp;
end
end;
procedure PrintList();
begin
var p := first;
while p<>nil do
begin
Print(p.data);
p := p.next;
end;
end;
procedure PrintBack();
begin
var p := last;
while p<>nil do
begin
Print(p.data);
p := p.prev;
end;
end;
end;
begin
var lst := new MyLinkedList<integer>;
lst.AddFirst(2); lst.AddFirst(3);
lst.AddLast(5);
lst.AddAfter(lst.first,555);
lst.PrintList;
Println;
lst.PrintBack;
end.