-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDequeWithCustomType.lpr
More file actions
46 lines (38 loc) · 968 Bytes
/
Copy pathDequeWithCustomType.lpr
File metadata and controls
46 lines (38 loc) · 968 Bytes
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
program DequeWithCustomType;
{$mode objfpc}{$H+}{$J-}
{$modeSwitch advancedrecords}
uses
ThreadSafeCollections.Deque;
type
TPerson = record
Name: string;
Age: Integer;
public
constructor Create(NewName: string; NewAge: Integer);
end;
constructor TPerson.Create(NewName: string; NewAge: Integer);
begin
Name := NewName;
Age := NewAge;
end;
var
Deque: specialize TThreadSafeDeque<TPerson>;
Person: TPerson;
begin
Deque := specialize TThreadSafeDeque<TPerson>.Create;
try
// Add items to the front and back
Deque.PushFront(TPerson.Create('Alice', 30));
Deque.PushBack(TPerson.Create('Bob', 25));
// Remove items from the front and back
if Deque.TryPopFront(Person) then
WriteLn('Popped from front: ', Person.Name);
if Deque.TryPopBack(Person) then
WriteLn('Popped from back: ', Person.Name);
finally
Deque.Free;
end;
// Pause console
WriteLn('Press enter to quit');
ReadLn;
end.