Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
39
Task/Queue-Definition/PascalABC.NET/queue-definition.pas
Normal file
39
Task/Queue-Definition/PascalABC.NET/queue-definition.pas
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
type
|
||||
Node<T> = auto class
|
||||
data: T;
|
||||
next: Node<T>;
|
||||
end;
|
||||
MyQueue<T> = class
|
||||
head,tail: Node<T>;
|
||||
public
|
||||
procedure Enqueue(x: T);
|
||||
begin
|
||||
if tail = nil then
|
||||
begin
|
||||
tail := new Node<T>(x,nil);
|
||||
head := tail;
|
||||
end
|
||||
else
|
||||
begin
|
||||
tail.next := new Node<T>(x,nil);
|
||||
tail := tail.next;
|
||||
end;
|
||||
end;
|
||||
function Dequeue(): T;
|
||||
begin
|
||||
Result := head.data;
|
||||
head := head.Next;
|
||||
if head = nil then
|
||||
tail := nil;
|
||||
end;
|
||||
function IsEmpty: boolean := head = nil;
|
||||
end;
|
||||
|
||||
begin
|
||||
var q := new MyQueue<integer>;
|
||||
for var i:=1 to 5 do
|
||||
q.Enqueue(i);
|
||||
while not q.IsEmpty do
|
||||
Print(q.Dequeue);
|
||||
Print(q.IsEmpty);
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue